Merge "Address code warnings in the android.app package."
diff --git a/core/java/android/app/Activity.java b/core/java/android/app/Activity.java
index d24b677..e85fa9d 100644
--- a/core/java/android/app/Activity.java
+++ b/core/java/android/app/Activity.java
@@ -959,7 +959,7 @@
private int mDefaultKeyMode = DEFAULT_KEYS_DISABLE;
private SpannableStringBuilder mDefaultKeySsb = null;
- private ActivityManager.TaskDescription mTaskDescription =
+ private final ActivityManager.TaskDescription mTaskDescription =
new ActivityManager.TaskDescription();
protected static final int[] FOCUSED_STATE_SET = {com.android.internal.R.attr.state_focused};
@@ -970,7 +970,7 @@
private Thread mUiThread;
@UnsupportedAppUsage
- ActivityTransitionState mActivityTransitionState = new ActivityTransitionState();
+ final ActivityTransitionState mActivityTransitionState = new ActivityTransitionState();
SharedElementCallback mEnterTransitionListener = SharedElementCallback.NULL_CALLBACK;
SharedElementCallback mExitTransitionListener = SharedElementCallback.NULL_CALLBACK;
@@ -1839,7 +1839,7 @@
final int numDialogs = ids.length;
mManagedDialogs = new SparseArray<ManagedDialog>(numDialogs);
for (int i = 0; i < numDialogs; i++) {
- final Integer dialogId = ids[i];
+ final int dialogId = ids[i];
Bundle dialogState = b.getBundle(savedDialogKeyFor(dialogId));
if (dialogState != null) {
// Calling onRestoreInstanceState() below will invoke dispatchOnCreate
@@ -1909,7 +1909,7 @@
* <code>persistAcrossReboots</code>.
*
* @param savedInstanceState The data most recently supplied in {@link #onSaveInstanceState}
- * @param persistentState The data caming from the PersistableBundle first
+ * @param persistentState The data coming from the PersistableBundle first
* saved in {@link #onSaveInstanceState(Bundle, PersistableBundle)}.
*
* @see #onCreate
@@ -5058,7 +5058,7 @@
* This hook is called when the user signals the desire to start a search.
*
* <p>You can use this function as a simple way to launch the search UI, in response to a
- * menu item, search button, or other widgets within your activity. Unless overidden,
+ * menu item, search button, or other widgets within your activity. Unless overridden,
* calling this function is the same as calling
* {@link #startSearch startSearch(null, false, null, false)}, which launches
* search for the current activity as specified in its manifest, see {@link SearchManager}.
@@ -8797,7 +8797,7 @@
* @see Activity#convertFromTranslucent()
* @see Activity#convertToTranslucent(TranslucentConversionListener, ActivityOptions)
*/
- public void onTranslucentConversionComplete(boolean drawComplete);
+ void onTranslucentConversionComplete(boolean drawComplete);
}
private void dispatchRequestPermissionsResult(int requestCode, Intent data) {
@@ -8920,7 +8920,7 @@
/**
* Registers remote animations per transition type for this activity.
*
- * @param definition The remote animation definition that defines which transition whould run
+ * @param definition The remote animation definition that defines which transition would run
* which remote animation.
* @hide
*/
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java
index 5ba7a4c..a1e4dbf 100644
--- a/core/java/android/app/ActivityThread.java
+++ b/core/java/android/app/ActivityThread.java
@@ -266,7 +266,6 @@
implements ActivityThreadInternal {
/** @hide */
public static final String TAG = "ActivityThread";
- private static final android.graphics.Bitmap.Config THUMBNAIL_FORMAT = Bitmap.Config.RGB_565;
static final boolean localLOGV = false;
static final boolean DEBUG_MESSAGES = false;
/** @hide */
@@ -368,7 +367,7 @@
private final AtomicInteger mNumLaunchingActivities = new AtomicInteger();
@GuardedBy("mAppThread")
private int mLastProcessState = PROCESS_STATE_UNKNOWN;
- ArrayList<WeakReference<AssistStructure>> mLastAssistStructures = new ArrayList<>();
+ final ArrayList<WeakReference<AssistStructure>> mLastAssistStructures = new ArrayList<>();
private int mLastSessionId;
final ArrayMap<IBinder, CreateServiceData> mServicesData = new ArrayMap<>();
@UnsupportedAppUsage
@@ -564,7 +563,7 @@
Configuration createdConfig;
Configuration overrideConfig;
// Used for consolidating configs before sending on to Activity.
- private Configuration tmpConfig = new Configuration();
+ private final Configuration tmpConfig = new Configuration();
// Callback used for updating activity override config and camera compat control state.
ViewRootImpl.ActivityConfigCallback activityConfigCallback;
ActivityClientRecord nextIdle;
@@ -769,7 +768,7 @@
}
}
- final class ProviderClientRecord {
+ static final class ProviderClientRecord {
final String[] mNames;
@UnsupportedAppUsage
final IContentProvider mProvider;
@@ -796,7 +795,7 @@
}
@UnsupportedAppUsage
- Intent intent;
+ final Intent intent;
@UnsupportedAppUsage
ActivityInfo info;
@UnsupportedAppUsage
@@ -3336,11 +3335,8 @@
public void registerOnActivityPausedListener(Activity activity,
OnActivityPausedListener listener) {
synchronized (mOnPauseListeners) {
- ArrayList<OnActivityPausedListener> list = mOnPauseListeners.get(activity);
- if (list == null) {
- list = new ArrayList<OnActivityPausedListener>();
- mOnPauseListeners.put(activity, list);
- }
+ ArrayList<OnActivityPausedListener> list =
+ mOnPauseListeners.computeIfAbsent(activity, k -> new ArrayList<>());
list.add(listener);
}
}
@@ -5400,7 +5396,7 @@
/** Core implementation of activity destroy call. */
void performDestroyActivity(ActivityClientRecord r, boolean finishing,
int configChanges, boolean getNonConfigInstance, String reason) {
- Class<? extends Activity> activityClass = null;
+ Class<? extends Activity> activityClass;
if (localLOGV) Slog.v(TAG, "Performing finish of " + r);
activityClass = r.activity.getClass();
r.activity.mConfigChangeFlags |= configChanges;
@@ -7051,7 +7047,7 @@
// Note that we cannot hold the lock while acquiring and installing the
// provider since it might take a long time to run and it could also potentially
// be re-entrant in the case where the provider is in the same process.
- ContentProviderHolder holder = null;
+ ContentProviderHolder holder;
final ProviderKey key = getGetProviderKey(auth, userId);
try {
synchronized (key) {
@@ -7105,11 +7101,7 @@
private ProviderKey getGetProviderKey(String auth, int userId) {
final ProviderKey key = new ProviderKey(auth, userId);
synchronized (mGetProviderKeys) {
- ProviderKey lock = mGetProviderKeys.get(key);
- if (lock == null) {
- lock = key;
- mGetProviderKeys.put(key, lock);
- }
+ ProviderKey lock = mGetProviderKeys.computeIfAbsent(key, k -> k);
return lock;
}
}
@@ -7744,7 +7736,7 @@
if (!DEPRECATE_DATA_COLUMNS) return;
// Install interception and make sure it sticks!
- Os def = null;
+ Os def;
do {
def = Os.getDefault();
} while (!Os.compareAndSetDefault(def, new AndroidOs(def)));
diff --git a/core/java/android/app/AliasActivity.java b/core/java/android/app/AliasActivity.java
index 37be901..f266769 100644
--- a/core/java/android/app/AliasActivity.java
+++ b/core/java/android/app/AliasActivity.java
@@ -16,9 +16,6 @@
package android.app;
-import org.xmlpull.v1.XmlPullParser;
-import org.xmlpull.v1.XmlPullParserException;
-
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
@@ -29,13 +26,16 @@
import com.android.internal.util.XmlUtils;
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+
import java.io.IOException;
/**
* Stub activity that launches another activity (and then finishes itself)
* based on information in its component's manifest meta-data. This is a
* simple way to implement an alias-like mechanism.
- *
+ *
* To use this activity, you should include in the manifest for the associated
* component an entry named "android.app.alias". It is a reference to an XML
* resource describing an intent that launches the real application.
@@ -51,11 +51,11 @@
* {@hide}
*/
public final String ALIAS_META_DATA = "android.app.alias";
-
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
-
+
XmlResourceParser parser = null;
try {
ActivityInfo ai = getPackageManager().getActivityInfo(
@@ -66,21 +66,17 @@
throw new RuntimeException("Alias requires a meta-data field "
+ ALIAS_META_DATA);
}
-
+
Intent intent = parseAlias(parser);
if (intent == null) {
throw new RuntimeException(
"No <intent> tag found in alias description");
}
-
+
startActivity(intent);
finish();
-
- } catch (PackageManager.NameNotFoundException e) {
- throw new RuntimeException("Error parsing alias", e);
- } catch (XmlPullParserException e) {
- throw new RuntimeException("Error parsing alias", e);
- } catch (IOException e) {
+
+ } catch (PackageManager.NameNotFoundException | XmlPullParserException | IOException e) {
throw new RuntimeException("Error parsing alias", e);
} finally {
if (parser != null) parser.close();
@@ -90,21 +86,21 @@
private Intent parseAlias(XmlPullParser parser)
throws XmlPullParserException, IOException {
AttributeSet attrs = Xml.asAttributeSet(parser);
-
+
Intent intent = null;
-
+
int type;
while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
&& type != XmlPullParser.START_TAG) {
}
-
+
String nodeName = parser.getName();
if (!"alias".equals(nodeName)) {
throw new RuntimeException(
"Alias meta-data must start with <alias> tag; found"
+ nodeName + " at " + parser.getPositionDescription());
}
-
+
int outerDepth = parser.getDepth();
while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
&& (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
@@ -120,8 +116,8 @@
XmlUtils.skipCurrentTag(parser);
}
}
-
+
return intent;
}
-
+
}
diff --git a/core/java/android/app/SearchableInfo.java b/core/java/android/app/SearchableInfo.java
index bd5d105..05742e6 100644
--- a/core/java/android/app/SearchableInfo.java
+++ b/core/java/android/app/SearchableInfo.java
@@ -535,7 +535,7 @@
*/
public static SearchableInfo getActivityMetaData(Context context, ActivityInfo activityInfo,
int userId) {
- Context userContext = null;
+ Context userContext;
try {
userContext = context.createPackageContextAsUser("system", 0,
new UserHandle(userId));
diff --git a/core/java/android/app/WallpaperManager.java b/core/java/android/app/WallpaperManager.java
index dea1a05..75b450d 100644
--- a/core/java/android/app/WallpaperManager.java
+++ b/core/java/android/app/WallpaperManager.java
@@ -1629,7 +1629,6 @@
mContext.getUserId());
if (fd != null) {
FileOutputStream fos = null;
- boolean ok = false;
try {
fos = new ParcelFileDescriptor.AutoCloseOutputStream(fd);
copyStreamToWallpaperFile(resources.openRawResource(resid), fos);