Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-23802] Android: expose sustainedPerformancemode for future development #8709

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
@Kroll.proxy(creatableInModule=UIModule.class, propertyAccessors={
TiC.PROPERTY_MODAL,
TiC.PROPERTY_WINDOW_PIXEL_FORMAT,
TiC.PROPERTY_FLAG_SECURE
TiC.PROPERTY_FLAG_SECURE,
TiC.PROPERTY_SUSTAINED_PERFORMANCE_MODE
})
public class WindowProxy extends TiWindowProxy implements TiActivityWindow
{
Expand All @@ -77,6 +78,7 @@ public WindowProxy()
{
super();
defaultValues.put(TiC.PROPERTY_WINDOW_PIXEL_FORMAT, PixelFormat.UNKNOWN);
defaultValues.put(TiC.PROPERTY_SUSTAINED_PERFORMANCE_MODE, false);
}

@Override
Expand Down Expand Up @@ -164,6 +166,10 @@ protected void handleOpen(KrollDict options)
topActivity.startActivity(intent);
}
}

if (options.containsKey(TiC.PROPERTY_SUSTAINED_PERFORMANCE_MODE)) {
setSustainedPerformanceMode((Boolean) options.get(TiC.PROPERTY_SUSTAINED_PERFORMANCE_MODE));
}
}

@Override
Expand Down Expand Up @@ -384,6 +390,17 @@ public void onPropertyChanged(String name, Object value)

super.onPropertyChanged(name, value);
}

@Kroll.setProperty @Kroll.method
public void setSustainedPerformanceMode(boolean mode) {
setProperty(TiC.PROPERTY_SUSTAINED_PERFORMANCE_MODE, mode);
windowActivity.get().setSustainModeOn(mode);
}

@Kroll.getProperty @Kroll.method
public boolean getSustainedPerformanceMode() {
return (Boolean) getProperty(TiC.PROPERTY_SUSTAINED_PERFORMANCE_MODE);
}

@Override
@Kroll.setProperty(retain=false) @Kroll.method
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
package org.appcelerator.titanium;

import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Stack;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;

import android.content.Context;
import android.os.PowerManager;
import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.KrollFunction;
import org.appcelerator.kroll.KrollObject;
Expand Down Expand Up @@ -95,6 +95,7 @@ public abstract class TiBaseActivity extends AppCompatActivity
private TiWeakList<OnCreateOptionsMenuEvent> onCreateOptionsMenuListeners = new TiWeakList<OnCreateOptionsMenuEvent>();
private TiWeakList<OnPrepareOptionsMenuEvent> onPrepareOptionsMenuListeners = new TiWeakList<OnPrepareOptionsMenuEvent>();
private APSAnalytics analytics = APSAnalytics.getInstance();
private boolean sustainModeOn = false;


public static class PermissionContextData {
Expand Down Expand Up @@ -677,7 +678,7 @@ protected void onCreate(Bundle savedInstanceState)
activityProxy.fireEvent(TiC.EVENT_CREATE, null);
}

// set the current activity back to what it was originally
// set the current activity back to what it was originally
tiApp.setCurrentActivity(this, tempCurrentActivity);

// If user changed the layout during app.js load, keep that
Expand Down Expand Up @@ -1733,4 +1734,20 @@ public static boolean isUnsupportedReLaunch(Activity activity, Bundle savedInsta
}
return false;
}

public boolean hasSustainMode()
{
PowerManager manager = (PowerManager) getSystemService(Context.POWER_SERVICE);
return manager.isSustainedPerformanceModeSupported();
}

public void setSustainModeOn(boolean sustainModeOn)
{
if (!hasSustainMode()) {
Log.w(TAG, "sustainedPerformanceMode is not supported on this device");
} else if (this.sustainModeOn != sustainModeOn) {
getWindow().setSustainedPerformanceMode(sustainModeOn);
this.sustainModeOn = sustainModeOn;
}
}
}
5 changes: 5 additions & 0 deletions android/titanium/src/java/org/appcelerator/titanium/TiC.java
Original file line number Diff line number Diff line change
Expand Up @@ -2587,6 +2587,11 @@ public class TiC
* @module.api
*/
public static final String PROPERTY_SUMMARY_TEXT = "summaryText";

/**
@module.api
*/
public static final String PROPERTY_SUSTAINED_PERFORMANCE_MODE = "sustainedPerformanceMode";

/**
* @module.api
Expand Down
17 changes: 17 additions & 0 deletions apidoc/Titanium/UI/Window.yml
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,23 @@ properties:
since: "3.1.3"
platforms: [iphone,ipad]

- name: sustainedPerformanceMode
summary: Maintain a sustainable level of performance.
description: |
Performance can fluctuate dramatically for long-running apps, because the system throttles
system-on-chip engines as device components reach their temperature limits. This fluctuation
presents a moving target for app developers creating high-performance, long-running apps.

Setting this feature to true will set sustained performance mode for the corresponding window.
If property is undefined then it defaults to false.

Note: feature is only available on supported devices and functionality is experimental and
subject to change in future releases. See [Android docs](https://developer.android.com/about/versions/nougat/android-7.0.html#sustained_performance_api) and [Google VR docs](https://developers.google.com/vr/android/ndk/jni/reference/com/google/vr/ndk/base/AndroidCompat.html#setSustainedPerformanceMode(Activity, boolean)) for further info.
type: Boolean
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The lines are still too long. Example of proper line breaks:

Performance can fluctuate dramatically for long-running apps, because the system throttles 
system-on-chip engines as device components reach their temperature limits. This fluctuation 
presents a moving target for app developers creating high-performance, long-running apps.
     
Setting this feature to true will set sustained performance mode for the corresponding window. 
If the property is undefined it defaults to false.
        
Note: feature is only available on supported devices and functionality is experimental and 
subject to change in future releases. See the [Android docs](https://developer.android.com/about/versions/nougat/android-7.0.html#sustained_performance_api) and [Google VR docs](https://developers.google.com/vr/android/ndk/jni/reference/com/google/vr/ndk/base/AndroidCompat.html#setSustainedPerformanceMode(Activity, boolean)) for further info.

Note that I did not break the last names, since the links cause the length there

since: "6.1.0"
platforms: [android]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add osver: {android: {min: "7.0"}} ? Rest looks cool to me!

osver: {android: {min: "7.0"}}

- name: swipeToClose
summary: Boolean value indicating if the user should be able to close a window using a swipe gesture.
description: |
Expand Down