use of android.content.pm.PackageManager.NameNotFoundException in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class AppPermissions method loadPermissionGroups.
private void loadPermissionGroups() {
mGroups.clear();
if (mPackageInfo.requestedPermissions == null) {
return;
}
final boolean appSupportsRuntimePermissions = appSupportsRuntime(mPackageInfo.applicationInfo);
for (int i = 0; i < mPackageInfo.requestedPermissions.length; i++) {
String requestedPerm = mPackageInfo.requestedPermissions[i];
final PermissionInfo permInfo;
try {
permInfo = mContext.getPackageManager().getPermissionInfo(requestedPerm, 0);
} catch (NameNotFoundException e) {
Log.w(TAG, "Unknown permission: " + requestedPerm);
continue;
}
String permName = permInfo.name;
String groupName = permInfo.group != null ? permInfo.group : permName;
PermissionGroup group = mGroups.get(groupName);
if (group == null) {
group = new PermissionGroup();
mGroups.put(groupName, group);
}
final boolean runtime = appSupportsRuntimePermissions && permInfo.protectionLevel == PermissionInfo.PROTECTION_DANGEROUS;
final boolean granted = (mPackageInfo.requestedPermissionsFlags[i] & PackageInfo.REQUESTED_PERMISSION_GRANTED) != 0;
Permission permission = new Permission(runtime, granted);
group.addPermission(permission, permName);
}
// Only care about runtime perms for now.
for (int i = mGroups.size() - 1; i >= 0; i--) {
if (!mGroups.valueAt(i).mHasRuntimePermissions) {
mGroups.removeAt(i);
}
}
}
use of android.content.pm.PackageManager.NameNotFoundException in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class AppOpsDetails method refreshUi.
private boolean refreshUi() {
if (mPackageInfo == null) {
return false;
}
setAppLabelAndIcon(mPackageInfo);
Resources res = getActivity().getResources();
mOperationsSection.removeAllViews();
String lastPermGroup = "";
boolean isPlatformSigned = isPlatformSigned();
for (AppOpsState.OpsTemplate tpl : AppOpsState.ALL_TEMPLATES) {
/* If we are platform signed, only show the root switch, this
* one is safe to toggle while other permission-based ones could
* certainly cause system-wide problems
*/
if (isPlatformSigned && tpl != AppOpsState.SU_TEMPLATE) {
continue;
}
List<AppOpsState.AppOpEntry> entries = mState.buildState(tpl, mPackageInfo.applicationInfo.uid, mPackageInfo.packageName);
for (final AppOpsState.AppOpEntry entry : entries) {
final AppOpsManager.OpEntry firstOp = entry.getOpEntry(0);
final View view = mInflater.inflate(R.layout.app_ops_details_item, mOperationsSection, false);
mOperationsSection.addView(view);
String perm = AppOpsManager.opToPermission(firstOp.getOp());
if (perm != null) {
try {
PermissionInfo pi = mPm.getPermissionInfo(perm, 0);
if (pi.group != null && !lastPermGroup.equals(pi.group)) {
lastPermGroup = pi.group;
PermissionGroupInfo pgi = mPm.getPermissionGroupInfo(pi.group, 0);
if (pgi.icon != 0) {
((ImageView) view.findViewById(R.id.op_icon)).setImageDrawable(pgi.loadIcon(mPm));
}
}
} catch (NameNotFoundException e) {
}
}
((TextView) view.findViewById(R.id.op_name)).setText(entry.getSwitchText(mState));
((TextView) view.findViewById(R.id.op_counts)).setText(entry.getCountsText(res));
((TextView) view.findViewById(R.id.op_time)).setText(entry.getTimeText(res, true));
Spinner sp = (Spinner) view.findViewById(R.id.spinnerWidget);
sp.setVisibility(View.GONE);
Switch sw = (Switch) view.findViewById(R.id.switchWidget);
sw.setVisibility(View.GONE);
final int switchOp = AppOpsManager.opToSwitch(firstOp.getOp());
int mode = mAppOps.checkOpNoThrow(switchOp, entry.getPackageOps().getUid(), entry.getPackageOps().getPackageName());
sp.setSelection(modeToPosition(mode));
sp.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() {
boolean firstMode = true;
@Override
public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
if (firstMode) {
firstMode = false;
return;
}
mAppOps.setMode(switchOp, entry.getPackageOps().getUid(), entry.getPackageOps().getPackageName(), positionToMode(position));
}
@Override
public void onNothingSelected(AdapterView<?> parentView) {
// Do nothing
}
});
sw.setChecked(mAppOps.checkOpNoThrow(switchOp, entry.getPackageOps().getUid(), entry.getPackageOps().getPackageName()) == AppOpsManager.MODE_ALLOWED);
sw.setOnCheckedChangeListener(new Switch.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mAppOps.setMode(switchOp, entry.getPackageOps().getUid(), entry.getPackageOps().getPackageName(), isChecked ? AppOpsManager.MODE_ALLOWED : AppOpsManager.MODE_IGNORED);
}
});
if (AppOpsManager.isStrictOp(switchOp)) {
sp.setVisibility(View.VISIBLE);
} else {
sw.setVisibility(View.VISIBLE);
}
}
}
return true;
}
use of android.content.pm.PackageManager.NameNotFoundException in project android_frameworks_base by ResurrectionRemix.
the class Activity method shouldUpRecreateTask.
/**
* Returns true if the app should recreate the task when navigating 'up' from this activity
* by using targetIntent.
*
* <p>If this method returns false the app can trivially call
* {@link #navigateUpTo(Intent)} using the same parameters to correctly perform
* up navigation. If this method returns false, the app should synthesize a new task stack
* by using {@link TaskStackBuilder} or another similar mechanism to perform up navigation.</p>
*
* @param targetIntent An intent representing the target destination for up navigation
* @return true if navigating up should recreate a new task stack, false if the same task
* should be used for the destination
*/
public boolean shouldUpRecreateTask(Intent targetIntent) {
try {
PackageManager pm = getPackageManager();
ComponentName cn = targetIntent.getComponent();
if (cn == null) {
cn = targetIntent.resolveActivity(pm);
}
ActivityInfo info = pm.getActivityInfo(cn, 0);
if (info.taskAffinity == null) {
return false;
}
return ActivityManagerNative.getDefault().shouldUpRecreateTask(mToken, info.taskAffinity);
} catch (RemoteException e) {
return false;
} catch (NameNotFoundException e) {
return false;
}
}
use of android.content.pm.PackageManager.NameNotFoundException in project android_frameworks_base by ResurrectionRemix.
the class Activity method getParentActivityIntent.
/**
* Obtain an {@link Intent} that will launch an explicit target activity specified by
* this activity's logical parent. The logical parent is named in the application's manifest
* by the {@link android.R.attr#parentActivityName parentActivityName} attribute.
* Activity subclasses may override this method to modify the Intent returned by
* super.getParentActivityIntent() or to implement a different mechanism of retrieving
* the parent intent entirely.
*
* @return a new Intent targeting the defined parent of this activity or null if
* there is no valid parent.
*/
@Nullable
public Intent getParentActivityIntent() {
final String parentName = mActivityInfo.parentActivityName;
if (TextUtils.isEmpty(parentName)) {
return null;
}
// If the parent itself has no parent, generate a main activity intent.
final ComponentName target = new ComponentName(this, parentName);
try {
final ActivityInfo parentInfo = getPackageManager().getActivityInfo(target, 0);
final String parentActivity = parentInfo.parentActivityName;
final Intent parentIntent = parentActivity == null ? Intent.makeMainActivity(target) : new Intent().setComponent(target);
return parentIntent;
} catch (NameNotFoundException e) {
Log.e(TAG, "getParentActivityIntent: bad parentActivityName '" + parentName + "' in manifest");
return null;
}
}
use of android.content.pm.PackageManager.NameNotFoundException in project android_frameworks_base by ResurrectionRemix.
the class DevicePolicyManagerService method clearDeviceOwner.
@Override
public void clearDeviceOwner(String packageName) {
Preconditions.checkNotNull(packageName, "packageName is null");
final int callingUid = mInjector.binderGetCallingUid();
try {
int uid = mContext.getPackageManager().getPackageUidAsUser(packageName, UserHandle.getUserId(callingUid));
if (uid != callingUid) {
throw new SecurityException("Invalid packageName");
}
} catch (NameNotFoundException e) {
throw new SecurityException(e);
}
synchronized (this) {
final ComponentName deviceOwnerComponent = mOwners.getDeviceOwnerComponent();
final int deviceOwnerUserId = mOwners.getDeviceOwnerUserId();
if (!mOwners.hasDeviceOwner() || !deviceOwnerComponent.getPackageName().equals(packageName) || (deviceOwnerUserId != UserHandle.getUserId(callingUid))) {
throw new SecurityException("clearDeviceOwner can only be called by the device owner");
}
enforceUserUnlocked(deviceOwnerUserId);
final ActiveAdmin admin = getDeviceOwnerAdminLocked();
long ident = mInjector.binderClearCallingIdentity();
try {
clearDeviceOwnerLocked(admin, deviceOwnerUserId);
removeActiveAdminLocked(deviceOwnerComponent, deviceOwnerUserId);
} finally {
mInjector.binderRestoreCallingIdentity(ident);
}
Slog.i(LOG_TAG, "Device owner removed: " + deviceOwnerComponent);
}
}
Aggregations