import android.content.DialogInterface;
import android.content.Intent;
import android.content.Loader;
+import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
+import com.android.settings.cyanogenmod.ProtectedAppsReceiver;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.os.BatterySipper;
// Menu identifiers
public static final int UNINSTALL_ALL_USERS_MENU = 1;
public static final int UNINSTALL_UPDATES = 2;
+ public static final int OPEN_PROTECTED_APPS = 3;
// Result code identifiers
public static final int REQUEST_UNINSTALL = 0;
private static final int SUB_INFO_FRAGMENT = 1;
+ public static final int REQUEST_TOGGLE_PROTECTION = 3;
private static final int LOADER_CHART_DATA = 2;
enabled = false;
}
+ // This is a protected app component.
+ // You cannot a uninstall a protected component
+ if (mPackageInfo.applicationInfo.protect) {
+ enabled = false;
+ }
+
mUninstallButton.setEnabled(enabled);
if (enabled) {
// Register listener
.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
menu.add(0, UNINSTALL_ALL_USERS_MENU, 1, R.string.uninstall_all_users_text)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
+ menu.add(0, OPEN_PROTECTED_APPS, Menu.NONE, R.string.protected_apps)
+ .setIcon(getResources().getDrawable(R.drawable.folder_lock))
+ .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
}
@Override
menu.findItem(UNINSTALL_ALL_USERS_MENU).setVisible(showIt);
mUpdatedSysApp = (mAppEntry.info.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0;
menu.findItem(UNINSTALL_UPDATES).setVisible(mUpdatedSysApp && !mAppControlRestricted);
+
+ menu.findItem(OPEN_PROTECTED_APPS).setVisible(mPackageInfo != null &&
+ mPackageInfo.applicationInfo != null && mPackageInfo.applicationInfo.protect);
}
@Override
case UNINSTALL_UPDATES:
showDialogInner(DLG_FACTORY_RESET, 0);
return true;
+ case OPEN_PROTECTED_APPS:
+ // Verify protection for toggling protected component status
+ Intent protectedApps = new Intent(getActivity(), LockPatternActivity.class);
+ startActivityForResult(protectedApps, REQUEST_TOGGLE_PROTECTION);
}
return false;
}
if (!refreshUi()) {
setIntentAndFinish(true, true);
}
+ } else if (requestCode == REQUEST_TOGGLE_PROTECTION) {
+ switch (resultCode) {
+ case Activity.RESULT_OK:
+ new ToggleProtectedAppComponents().execute();
+ break;
+ case Activity.RESULT_CANCELED:
+ // User failed to enter/confirm a lock pattern, do nothing
+ break;
+ }
+ }
+ }
+
+ private class ToggleProtectedAppComponents extends AsyncTask<Void, Void, Void> {
+ @Override
+ protected void onPostExecute(Void aVoid) {
+ getActivity().invalidateOptionsMenu();
+ if (!refreshUi()) {
+ setIntentAndFinish(true, true);
+ }
+ }
+
+ @Override
+ protected Void doInBackground(Void... params) {
+ ArrayList<ComponentName> components = new ArrayList<ComponentName>();
+ for (ActivityInfo aInfo : mPackageInfo.activities) {
+ components.add(new ComponentName(aInfo.packageName, aInfo.name));
+ }
+
+ ProtectedAppsReceiver.updateProtectedAppComponentsAndNotify(getActivity(),
+ components, PackageManager.COMPONENT_VISIBLE_STATUS);
+ return null;
}
}
final View appSnippet = mHeader.findViewById(R.id.app_snippet);
mState.ensureIcon(mAppEntry);
setupAppSnippet(appSnippet, mAppEntry.label, mAppEntry.icon,
- pkgInfo != null ? pkgInfo.versionName : null);
+ pkgInfo != null ? pkgInfo.versionName : null, pkgInfo.packageName);
}
private boolean signaturesMatch(String pkg1, String pkg2) {
}
private void checkForceStop() {
+ if (getActivity() == null || getActivity().isFinishing()) {
+ return;
+ }
+
if (mDpm.packageHasActiveAdmins(mPackageInfo.packageName)) {
// User can't force stop device admin.
updateForceStopButton(false);
}
public static void setupAppSnippet(View appSnippet, CharSequence label, Drawable icon,
- CharSequence versionName) {
+ CharSequence versionName, String packageName) {
LayoutInflater.from(appSnippet.getContext()).inflate(R.layout.widget_text_views,
(ViewGroup) appSnippet.findViewById(android.R.id.widget_frame));
// Version number of application
TextView appVersion = (TextView) appSnippet.findViewById(R.id.widget_text1);
+ if (packageName != null) {
+ TextView appPackage = (TextView) appSnippet.findViewById(R.id.widget_text2);
+ appPackage.setText(packageName);
+ appPackage.setSelected(true);
+ }
+
if (!TextUtils.isEmpty(versionName)) {
appVersion.setSelected(true);
appVersion.setVisibility(View.VISIBLE);
mPm.setApplicationEnabledSetting(mInfo.packageName, mState, 0);
return null;
}
+
+ @Override
+ protected void onPostExecute(Object o) {
+ if (mActivity.get() != null) {
+ mActivity.get().refreshUi();
+ }
+ }
}
private final LoaderCallbacks<ChartData> mDataCallbacks = new LoaderCallbacks<ChartData>() {
private final BroadcastReceiver mCheckKillProcessesReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
- updateForceStopButton(getResultCode() != Activity.RESULT_CANCELED);
+ if (getActivity() != null && !getActivity().isDestroyed()) {
+ updateForceStopButton(getResultCode() != Activity.RESULT_CANCELED);
+ }
}
};