private static void killProcessesAround(Activity activity) throws NameNotFoundException { ActivityManager am = (ActivityManager)activity.getSystemService(Context.ACTIVITY_SERVICE); String myProcessPrefix = activity.getApplicationInfo().processName; String myProcessName = activity.getPackageManager().getActivityInfo(activity.getComponentName(), 0).processName; for (ActivityManager.RunningAppProcessInfo proc : am.getRunningAppProcesses()) { if (proc.processName.startsWith(myProcessPrefix) && !proc.processName.equals(myProcessName)) { android.os.Process.killProcess(proc.pid); } } }
private void loadIcon(TypedArray a, PackageManager pm, ApplicationInfo appInfo) { if (mContext instanceof Activity) { try { mIcon = pm.getActivityIcon(((Activity) mContext).getComponentName()); } catch (NameNotFoundException e) { Log.e(TAG, "Failed to load app icon.", e); } } if (mIcon == null) { mIcon = appInfo.loadIcon(pm); } }
private void loadLogo(TypedArray a, PackageManager pm, ApplicationInfo appInfo) { if (mContext instanceof Activity) { try { mLogo = pm.getActivityLogo(((Activity) mContext).getComponentName()); } catch (NameNotFoundException e) { Log.e(TAG, "Failed to load app logo.", e); } } if (mLogo == null) { mLogo = appInfo.loadLogo(pm); } }
/** MCC + MNC are always present in config changes since Oreo. */ @Test @Config(minSdk = O) public void getActivityMetaData_configChangesAlwaysIncludesMccAndMnc() throws Exception { Activity activity = setupActivity(ShadowPackageManagerTest.ActivityWithConfigChanges.class); ActivityInfo activityInfo = activity.getPackageManager().getActivityInfo(activity.getComponentName(), 0); int configChanges = activityInfo.configChanges; assertThat(configChanges & ActivityInfo.CONFIG_MCC).isEqualTo(ActivityInfo.CONFIG_MCC); assertThat(configChanges & ActivityInfo.CONFIG_MNC).isEqualTo(ActivityInfo.CONFIG_MNC); }
@Test public void getActivityMetaData() throws Exception { Activity activity = setupActivity(ActivityWithMetadata.class); ActivityInfo activityInfo = packageManager.getActivityInfo( activity.getComponentName(), PackageManager.GET_ACTIVITIES | PackageManager.GET_META_DATA); assertThat(activityInfo.metaData.get("someName")).isEqualTo("someValue"); }
@Test public void getActivityMetaData_configChanges() throws Exception { Activity activity = setupActivity(ShadowPackageManagerTest.ActivityWithConfigChanges.class); ActivityInfo activityInfo = activity.getPackageManager().getActivityInfo(activity.getComponentName(), 0); int configChanges = activityInfo.configChanges; assertThat(configChanges & ActivityInfo.CONFIG_SCREEN_LAYOUT) .isEqualTo(ActivityInfo.CONFIG_SCREEN_LAYOUT); assertThat(configChanges & ActivityInfo.CONFIG_ORIENTATION) .isEqualTo(ActivityInfo.CONFIG_ORIENTATION); // Spot check a few other possible values that shouldn't be in the flags. assertThat(configChanges & ActivityInfo.CONFIG_FONT_SCALE).isEqualTo(0); assertThat(configChanges & ActivityInfo.CONFIG_SCREEN_SIZE).isEqualTo(0); }
ComponentName getBaseActivity() { for (WeakReference<Activity> activityWeakReference : mRunningActivities) { if (activityWeakReference == null) continue; Activity tmpActivity = activityWeakReference.get(); if (tmpActivity == null) continue; return tmpActivity.getComponentName(); } return null; }
ComponentName getBaseActivity() { for (WeakReference<Activity> activityWeakReference : mRunningActivities) { if (activityWeakReference == null) continue; Activity tmpActivity = activityWeakReference.get(); if (tmpActivity == null) continue; return tmpActivity.getComponentName(); } return null; }
@Override public void onMenuOpened(final Activity activity) { if (data.get(activity.getComponentName()).fullScreen) { activity.getWindow().clearFlags(FLAG_FULLSCREEN); } }
@Override public void onMenuClosed(final Activity activity) { if (data.get(activity.getComponentName()).fullScreen) { activity.getWindow().setFlags(FLAG_FULLSCREEN, FLAG_FULLSCREEN); } }
@Override public void setFullScreenMode(final Activity activity, final View view, final boolean fullScreen) { data.get(activity.getComponentName()).fullScreen = fullScreen; final Window w = activity.getWindow(); if (fullScreen) { w.setFlags(FLAG_FULLSCREEN, FLAG_FULLSCREEN); } else { w.clearFlags(FLAG_FULLSCREEN); } }
@Override public void onPause(final Activity activity) { if (data.get(activity.getComponentName()).fullScreen && data.get(activity.getComponentName()).fullScreenState.get()) { startSystemUI(activity); } }
private IntentBuilder(Activity launchingActivity) { mActivity = launchingActivity; mIntent = new Intent().setAction(Intent.ACTION_SEND); mIntent.putExtra(EXTRA_CALLING_PACKAGE, launchingActivity.getPackageName()); mIntent.putExtra(EXTRA_CALLING_ACTIVITY, launchingActivity.getComponentName()); mIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); }
@Override public void onMenuOpened(final Activity activity) { if (data.get(activity.getComponentName()).fullScreen && data.get(activity.getComponentName()).fullScreenState.get()) { startSystemUI(activity); } }
@Override public void onDestroy(final Activity activity) { if (data.get(activity.getComponentName()).fullScreen && data.get(activity.getComponentName()).fullScreenState.get()) { startSystemUI(activity); } }
@Override public void run() { try { final boolean result = execImpl(as); data.get(activity.getComponentName()).fullScreenState.set(result ? expected : !expected); } catch (final Throwable th) { LCTX.e("Changing full screen mode failed: " + th.getCause()); data.get(activity.getComponentName()).fullScreenState.set(!expected); } } })).start();
@Override public void onMenuOpened(final Activity activity) { if (!isTabletUi(activity)) { if (data.get(activity.getComponentName()).statusBarHidden) { activity.getWindow().clearFlags(FLAG_FULLSCREEN); } } }
protected void stopSystemUI(final Activity activity) { if (!isSystemUIRunning()) { data.get(activity.getComponentName()).fullScreenState.set(true); return; } final String su = getSuPath(); if (su == null) { data.get(activity.getComponentName()).fullScreenState.set(false); return; } exec(true, activity, su, "-c", "service call activity 79 s16 " + SYS_UI_PKG); }
protected void startSystemUI(final Activity activity) { if (isSystemUIRunning()) { data.get(activity.getComponentName()).fullScreenState.set(false); return; } exec(false, activity, AM_PATH, "startservice", "-n", SYS_UI.flattenToString()); }
public static void translateTitle(Activity activity) { if (isLocaleOverridden(activity)) { // http://stackoverflow.com/questions/22884068/troubles-with-activity-title-language try { int labelRes = activity.getPackageManager().getActivityInfo(activity.getComponentName(), 0).labelRes; activity.setTitle(labelRes); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } } }