am f4d4440f: am f7c184f0: am 3f98c0ce: Fix issue #21813831: Need API for asking to be added to power whitelist

* commit 'f4d4440fd4318a83ce83090a744171e336d6fd65':
  Fix issue #21813831: Need API for asking to be added to power whitelist
This commit is contained in:
Dianne Hackborn
2015-06-15 19:49:39 +00:00
committed by Android Git Automerger
3 changed files with 36 additions and 6 deletions

View File

@@ -956,6 +956,10 @@
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />
<data android:scheme="package" /> <data android:scheme="package" />
</intent-filter> </intent-filter>
<intent-filter android:priority="1">
<action android:name="android.settings.IGNORE_BATTERY_OPTIMIZATION_SETTINGS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data android:name="com.android.settings.FRAGMENT_CLASS" <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.applications.ManageApplications" /> android:value="com.android.settings.applications.ManageApplications" />
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED" <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"

View File

@@ -184,6 +184,7 @@ public class ManageApplications extends InstrumentedFragment
private String mCurrentPkgName; private String mCurrentPkgName;
private int mCurrentUid; private int mCurrentUid;
private boolean mFinishAfterDialog;
private Menu mOptionsMenu; private Menu mOptionsMenu;
@@ -240,12 +241,13 @@ public class ManageApplications extends InstrumentedFragment
mListType = LIST_TYPE_HIGH_POWER; mListType = LIST_TYPE_HIGH_POWER;
// Default to showing system. // Default to showing system.
mShowSystem = true; mShowSystem = true;
if (intent != null && Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS if (Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS.equals(intent.getAction())
.equals(intent.getAction())) { && intent.getData() != null) {
mCurrentPkgName = intent.getData().getSchemeSpecificPart(); mCurrentPkgName = intent.getData().getSchemeSpecificPart();
if (mCurrentPkgName != null) { if (mCurrentPkgName != null) {
mCurrentUid = mApplicationsState.getEntry(mCurrentPkgName, mCurrentUid = mApplicationsState.getEntry(mCurrentPkgName,
UserHandle.myUserId()).info.uid; UserHandle.myUserId()).info.uid;
mFinishAfterDialog = true;
startApplicationDetailsActivity(); startApplicationDetailsActivity();
} }
} }
@@ -427,6 +429,12 @@ public class ManageApplications extends InstrumentedFragment
if (requestCode == INSTALLED_APP_DETAILS && mCurrentPkgName != null) { if (requestCode == INSTALLED_APP_DETAILS && mCurrentPkgName != null) {
if (mListType == LIST_TYPE_NOTIFICATION) { if (mListType == LIST_TYPE_NOTIFICATION) {
mApplications.mExtraInfoBridge.forceUpdate(mCurrentPkgName, mCurrentUid); mApplications.mExtraInfoBridge.forceUpdate(mCurrentPkgName, mCurrentUid);
} else if (mListType == LIST_TYPE_HIGH_POWER) {
if (mFinishAfterDialog) {
getActivity().onBackPressed();
} else {
mApplications.mExtraInfoBridge.forceUpdate(mCurrentPkgName, mCurrentUid);
}
} else { } else {
mApplicationsState.requestSize(mCurrentPkgName, UserHandle.getUserId(mCurrentUid)); mApplicationsState.requestSize(mCurrentPkgName, UserHandle.getUserId(mCurrentUid));
} }
@@ -450,7 +458,8 @@ public class ManageApplications extends InstrumentedFragment
startAppInfoFragment(AppStorageSettings.class, R.string.storage_settings); startAppInfoFragment(AppStorageSettings.class, R.string.storage_settings);
break; break;
case LIST_TYPE_HIGH_POWER: case LIST_TYPE_HIGH_POWER:
HighPowerDetail.show(getActivity(), mCurrentPkgName); HighPowerDetail.show(this, mCurrentPkgName, INSTALLED_APP_DETAILS,
mFinishAfterDialog);
break; break;
// TODO: Figure out if there is a way where we can spin up the profile's settings // TODO: Figure out if there is a way where we can spin up the profile's settings
// process ahead of time, to avoid a long load of data when user clicks on a managed app. // process ahead of time, to avoid a long load of data when user clicks on a managed app.

View File

@@ -20,6 +20,7 @@ import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.Dialog; import android.app.Dialog;
import android.app.DialogFragment; import android.app.DialogFragment;
import android.app.Fragment;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener; import android.content.DialogInterface.OnClickListener;
@@ -39,10 +40,13 @@ import com.android.settingslib.applications.ApplicationsState.AppEntry;
public class HighPowerDetail extends DialogFragment implements OnClickListener { public class HighPowerDetail extends DialogFragment implements OnClickListener {
private static final String ARG_DEFAULT_ON = "default_on";
private final PowerWhitelistBackend mBackend = PowerWhitelistBackend.getInstance(); private final PowerWhitelistBackend mBackend = PowerWhitelistBackend.getInstance();
private String mPackageName; private String mPackageName;
private CharSequence mLabel; private CharSequence mLabel;
private boolean mDefaultOn;
private Adapter mAdapter; private Adapter mAdapter;
private int mSelectedIndex; private int mSelectedIndex;
@@ -57,12 +61,13 @@ public class HighPowerDetail extends DialogFragment implements OnClickListener {
} catch (NameNotFoundException e) { } catch (NameNotFoundException e) {
mLabel = mPackageName; mLabel = mPackageName;
} }
mDefaultOn = getArguments().getBoolean(ARG_DEFAULT_ON);
mAdapter = new Adapter(getContext(), R.layout.radio_with_summary); mAdapter = new Adapter(getContext(), R.layout.radio_with_summary);
mAdapter.add(new Pair<String, String>(getString(R.string.ignore_optimizations_on), mAdapter.add(new Pair<String, String>(getString(R.string.ignore_optimizations_on),
getString(R.string.ignore_optimizations_on_desc))); getString(R.string.ignore_optimizations_on_desc)));
mAdapter.add(new Pair<String, String>(getString(R.string.ignore_optimizations_off), mAdapter.add(new Pair<String, String>(getString(R.string.ignore_optimizations_off),
getString(R.string.ignore_optimizations_off_desc))); getString(R.string.ignore_optimizations_off_desc)));
mSelectedIndex = mBackend.isWhitelisted(mPackageName) ? 0 : 1; mSelectedIndex = mDefaultOn || mBackend.isWhitelisted(mPackageName) ? 0 : 1;
if (mBackend.isSysWhitelisted(mPackageName)) { if (mBackend.isSysWhitelisted(mPackageName)) {
mAdapter.setEnabled(1, false); mAdapter.setEnabled(1, false);
} }
@@ -97,6 +102,15 @@ public class HighPowerDetail extends DialogFragment implements OnClickListener {
} }
} }
@Override
public void onDismiss(DialogInterface dialog) {
super.onDismiss(dialog);
Fragment target = getTargetFragment();
if (target != null) {
target.onActivityResult(getTargetRequestCode(), 0, null);
}
}
public static CharSequence getSummary(Context context, AppEntry entry) { public static CharSequence getSummary(Context context, AppEntry entry) {
return getSummary(context, entry.info.packageName); return getSummary(context, entry.info.packageName);
} }
@@ -106,12 +120,15 @@ public class HighPowerDetail extends DialogFragment implements OnClickListener {
? R.string.high_power_on : R.string.high_power_off); ? R.string.high_power_on : R.string.high_power_off);
} }
public static void show(Activity activity, String packageName) { public static void show(Fragment caller, String packageName, int requestCode,
boolean defaultToOn) {
HighPowerDetail fragment = new HighPowerDetail(); HighPowerDetail fragment = new HighPowerDetail();
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putString(AppInfoBase.ARG_PACKAGE_NAME, packageName); args.putString(AppInfoBase.ARG_PACKAGE_NAME, packageName);
args.putBoolean(ARG_DEFAULT_ON, defaultToOn);
fragment.setArguments(args); fragment.setArguments(args);
fragment.show(activity.getFragmentManager(), HighPowerDetail.class.getSimpleName()); fragment.setTargetFragment(caller, requestCode);
fragment.show(caller.getFragmentManager(), HighPowerDetail.class.getSimpleName());
} }
private class Adapter extends ArrayAdapter<Pair<String, String>> { private class Adapter extends ArrayAdapter<Pair<String, String>> {