/** * Called by the system when the device configuration changes while your * activity is running. Note that this will <em>only</em> be called if * you have selected configurations you would like to handle with the * {@link android.R.attr#configChanges} attribute in your manifest. If * any configuration change occurs that is not selected to be reported * by that attribute, then instead of reporting it the system will stop * and restart the activity (to have it launched with the new * configuration). * * <p>At the time that this function has been called, your Resources * object will have been updated to return resource values matching the * new configuration. * * @param newConfig The new device configuration. */ public void onConfigurationChanged(Configuration newConfig) { if (DEBUG_LIFECYCLE) Slog.v(TAG, "onConfigurationChanged " + this + ": " + newConfig); mCalled = true; mFragments.dispatchConfigurationChanged(newConfig); if (mWindow != null) { // Pass the configuration changed event to the window mWindow.onConfigurationChanged(newConfig); } if (mActionBar != null) { // Do this last; the action bar will need to access // view changes from above. mActionBar.onConfigurationChanged(newConfig); } }
public List<FirewallIntentResolver> readRules (File xml, FileInputStream fis) { FirewallIntentResolver[] resolvers = new FirewallIntentResolver[3]; for (int i=0; i<resolvers.length; i++) { resolvers[i] = new FirewallIntentResolver(); } if (xml != null) { if (xml.getName().endsWith(".xml")) { readRules(xml, fis, resolvers); } } Slog.i(TAG, "Read new rules (A:" + resolvers[TYPE_ACTIVITY].filterSet().size() + " B:" + resolvers[TYPE_BROADCAST].filterSet().size() + " S:" + resolvers[TYPE_SERVICE].filterSet().size() + ")"); mActivityResolver = resolvers[TYPE_ACTIVITY]; mBroadcastResolver = resolvers[TYPE_BROADCAST]; mServiceResolver = resolvers[TYPE_SERVICE]; List<FirewallIntentResolver> list = new ArrayList<>(); Collections.addAll(list, mActivityResolver); Collections.addAll(list, mBroadcastResolver); Collections.addAll(list, mServiceResolver); return list; }
static boolean isPrivilegedApp(int callerUid, int callerPid) { if (callerUid == Process.SYSTEM_UID || callerUid == 0 || callerPid == Process.myPid() || callerPid == 0) { return true; } IPackageManager pm = AppGlobals.getPackageManager(); try { return (pm.getPrivateFlagsForUid(callerUid) & ApplicationInfo.PRIVATE_FLAG_PRIVILEGED) != 0; } catch (RemoteException ex) { Slog.e(IntentFirewall.TAG, "Remote exception while retrieving uid flags", ex); } return false; }
public List<FirewallIntentResolver> readRules (File xml) { FirewallIntentResolver[] resolvers = new FirewallIntentResolver[3]; for (int i=0; i<resolvers.length; i++) { resolvers[i] = new FirewallIntentResolver(); } if (xml != null) { if (xml.getName().endsWith(".xml")) { readRules(xml, resolvers); } } Slog.i(TAG, "Read new rules (A:" + resolvers[TYPE_ACTIVITY].filterSet().size() + " B:" + resolvers[TYPE_BROADCAST].filterSet().size() + " S:" + resolvers[TYPE_SERVICE].filterSet().size() + ")"); mActivityResolver = resolvers[TYPE_ACTIVITY]; mBroadcastResolver = resolvers[TYPE_BROADCAST]; mServiceResolver = resolvers[TYPE_SERVICE]; List<FirewallIntentResolver> list = new ArrayList<>(); Collections.addAll(list, mActivityResolver); Collections.addAll(list, mBroadcastResolver); Collections.addAll(list, mServiceResolver); return list; }
void removeFilterInternal(F f) { if (localLOGV) { Slog.v(TAG, "Removing filter: " + f); f.dump(new LogPrinter(Log.VERBOSE, TAG, Log.LOG_ID_SYSTEM), " "); Slog.v(TAG, " Cleaning Lookup Maps:"); } int numS = unregister_intent_filter(f, f.schemesIterator(), mSchemeToFilter, " Scheme: "); int numT = unregister_mime_types(f, " Type: "); if (numS == 0 && numT == 0) { unregister_intent_filter(f, f.actionsIterator(), mActionToFilter, " Action: "); } if (numT != 0) { unregister_intent_filter(f, f.actionsIterator(), mTypedActionToFilter, " TypedAction: "); } }
final void dispatchMultiWindowModeChanged(boolean isInMultiWindowMode) { if (DEBUG_LIFECYCLE) Slog.v(TAG, "dispatchMultiWindowModeChanged " + this + ": " + isInMultiWindowMode); mFragments.dispatchMultiWindowModeChanged(isInMultiWindowMode); if (mWindow != null) { mWindow.onMultiWindowModeChanged(); } onMultiWindowModeChanged(isInMultiWindowMode); }
/** * Called when the activity is starting. This is where most initialization * should go: calling {@link #setContentView(int)} to inflate the * activity's UI, using {@link #findViewById} to programmatically interact * with widgets in the UI, calling * {@link #managedQuery(android.net.Uri , String[], String, String[], String)} to retrieve * cursors for data being displayed, etc. * * <p>You can call {@link #finish} from within this function, in * which case onDestroy() will be immediately called without any of the rest * of the activity lifecycle ({@link #onStart}, {@link #onResume}, * {@link #onPause}, etc) executing. * * <p><em>Derived classes must call through to the super class's * implementation of this method. If they do not, an exception will be * thrown.</em></p> * * @param savedInstanceState If the activity is being re-initialized after * previously being shut down then this Bundle contains the data it most * recently supplied in {@link #onSaveInstanceState}. <b><i>Note: Otherwise it is null.</i></b> * * @see #onStart * @see #onSaveInstanceState * @see #onRestoreInstanceState * @see #onPostCreate */ @MainThread @CallSuper protected void onCreate(@Nullable Bundle savedInstanceState) { if (DEBUG_LIFECYCLE) Slog.v(TAG, "onCreate " + this + ": " + savedInstanceState); if (mLastNonConfigurationInstances != null) { mFragments.restoreLoaderNonConfig(mLastNonConfigurationInstances.loaders); } if (mActivityInfo.parentActivityName != null) { if (mActionBar == null) { mEnableDefaultActionBarUp = true; } else { mActionBar.setDefaultDisplayHomeAsUpEnabled(true); } } if (savedInstanceState != null) { Parcelable p = savedInstanceState.getParcelable(FRAGMENTS_TAG); mFragments.restoreAllState(p, mLastNonConfigurationInstances != null ? mLastNonConfigurationInstances.fragments : null); } mFragments.dispatchCreate(); getApplication().dispatchActivityCreated(this, savedInstanceState); if (mVoiceInteractor != null) { mVoiceInteractor.attachActivity(this); } mCalled = true; }
/** * Reads rules from all xml files (*.xml) in the given directory, and replaces our set of rules * with the newly read rules. * * We only check for files ending in ".xml", to allow for temporary files that are atomically * renamed to .xml * * All calls to this method from the file observer come through a handler and are inherently * serialized */ public List<FirewallIntentResolver> readRulesDir(File rulesDir) { FirewallIntentResolver[] resolvers = new FirewallIntentResolver[3]; for (int i=0; i<resolvers.length; i++) { resolvers[i] = new FirewallIntentResolver(); } File[] files = rulesDir.listFiles(); if (files != null) { for (int i=0; i<files.length; i++) { File file = files[i]; if (file.getName().endsWith(".xml")) { readRules(file, resolvers); } } } Slog.i(TAG, "Read new rules (A:" + resolvers[TYPE_ACTIVITY].filterSet().size() + " B:" + resolvers[TYPE_BROADCAST].filterSet().size() + " S:" + resolvers[TYPE_SERVICE].filterSet().size() + ")"); mActivityResolver = resolvers[TYPE_ACTIVITY]; mBroadcastResolver = resolvers[TYPE_BROADCAST]; mServiceResolver = resolvers[TYPE_SERVICE]; List<FirewallIntentResolver> list = new ArrayList<>(); Collections.addAll(list, mActivityResolver); Collections.addAll(list, mBroadcastResolver); Collections.addAll(list, mServiceResolver); return list; }
boolean signaturesMatch(int uid1, int uid2) { try { IPackageManager pm = AppGlobals.getPackageManager(); return pm.checkUidSignatures(uid1, uid2) == PackageManager.SIGNATURE_MATCH; } catch (RemoteException ex) { Slog.e(TAG, "Remote exception while checking signatures", ex); return false; } }
private final int unregister_mime_types(F filter, String prefix) { final Iterator<String> i = filter.typesIterator(); if (i == null) { return 0; } int num = 0; while (i.hasNext()) { String name = i.next(); num++; if (localLOGV) Slog.v(TAG, prefix + name); String baseName = name; final int slashpos = name.indexOf('/'); if (slashpos > 0) { baseName = name.substring(0, slashpos).intern(); } else { name = name + "/*"; } remove_all_objects(mTypeToFilter, name, filter); if (slashpos > 0) { remove_all_objects(mBaseTypeToFilter, baseName, filter); } else { remove_all_objects(mWildTypeToFilter, baseName, filter); } } return num; }
private final int register_intent_filter(F filter, Iterator<String> i, ArrayMap<String, F[]> dest, String prefix) { if (i == null) { return 0; } int num = 0; while (i.hasNext()) { String name = i.next(); num++; if (localLOGV) Slog.v(TAG, prefix + name); addFilter(dest, name, filter); } return num; }
private final int register_mime_types(F filter, String prefix) { final Iterator<String> i = filter.typesIterator(); if (i == null) { return 0; } int num = 0; while (i.hasNext()) { String name = i.next(); num++; if (localLOGV) Slog.v(TAG, prefix + name); String baseName = name; final int slashpos = name.indexOf('/'); if (slashpos > 0) { baseName = name.substring(0, slashpos).intern(); } else { name = name + "/*"; } addFilter(mTypeToFilter, name, filter); if (slashpos > 0) { addFilter(mBaseTypeToFilter, baseName, filter); } else { addFilter(mWildTypeToFilter, baseName, filter); } } return num; }
/** * Perform any final cleanup before an activity is destroyed. This can * happen either because the activity is finishing (someone called * {@link #finish} on it, or because the system is temporarily destroying * this instance of the activity to save space. You can distinguish * between these two scenarios with the {@link #isFinishing} method. * * <p><em>Note: do not count on this method being called as a place for * saving data! For example, if an activity is editing data in a content * provider, those edits should be committed in either {@link #onPause} or * {@link #onSaveInstanceState}, not here.</em> This method is usually implemented to * free resources like threads that are associated with an activity, so * that a destroyed activity does not leave such things around while the * rest of its application is still running. There are situations where * the system will simply kill the activity's hosting process without * calling this method (or any others) in it, so it should not be used to * do things that are intended to remain around after the process goes * away. * * <p><em>Derived classes must call through to the super class's * implementation of this method. If they do not, an exception will be * thrown.</em></p> * * @see #onPause * @see #onStop * @see #finish * @see #isFinishing */ @CallSuper protected void onDestroy() { if (DEBUG_LIFECYCLE) Slog.v(TAG, "onDestroy " + this); mCalled = true; // dismiss any dialogs we are managing. if (mManagedDialogs != null) { final int numDialogs = mManagedDialogs.size(); for (int i = 0; i < numDialogs; i++) { final ManagedDialog md = mManagedDialogs.valueAt(i); if (md.mDialog.isShowing()) { md.mDialog.dismiss(); } } mManagedDialogs = null; } // close any cursors we are managing. synchronized (mManagedCursors) { int numCursors = mManagedCursors.size(); for (int i = 0; i < numCursors; i++) { ManagedCursor c = mManagedCursors.get(i); if (c != null) { c.mCursor.close(); } } mManagedCursors.clear(); } // Close any open search dialog if (mSearchManager != null) { mSearchManager.stopSearch(); } if (mActionBar != null) { mActionBar.onDestroy(); } getApplication().dispatchActivityDestroyed(this); }
public void onLowMemory() { if (DEBUG_LIFECYCLE) Slog.v(TAG, "onLowMemory " + this); mCalled = true; mFragments.dispatchLowMemory(); }
public void onTrimMemory(int level) { if (DEBUG_LIFECYCLE) Slog.v(TAG, "onTrimMemory " + this + ": " + level); mCalled = true; mFragments.dispatchTrimMemory(level); }
final void dispatchPictureInPictureModeChanged(boolean isInPictureInPictureMode) { if (DEBUG_LIFECYCLE) Slog.v(TAG, "dispatchPictureInPictureModeChanged " + this + ": " + isInPictureInPictureMode); mFragments.dispatchPictureInPictureModeChanged(isInPictureInPictureMode); onPictureInPictureModeChanged(isInPictureInPictureMode); }