Update language to comply with Android's inclusive language guidance

See https://source.android.com/setup/contribute/respectful-code for reference

Bug: 161896447
Test: robotest & manual
Change-Id: I1eaa45b576913e57ad9728e3a6fc892c4cf9fdc7
This commit is contained in:
Edgar Wang
2020-08-03 15:48:11 +08:00
parent 867e9db69d
commit 41711581d6
5 changed files with 164 additions and 160 deletions

View File

@@ -139,62 +139,67 @@ public class RunningState {
int mSequence = 0;
final Comparator<RunningState.MergedItem> mBackgroundComparator
= new Comparator<RunningState.MergedItem>() {
@Override
public int compare(MergedItem lhs, MergedItem rhs) {
if (DEBUG_COMPARE) {
Log.i(TAG, "Comparing " + lhs + " with " + rhs);
Log.i(TAG, " Proc " + lhs.mProcess + " with " + rhs.mProcess);
Log.i(TAG, " UserId " + lhs.mUserId + " with " + rhs.mUserId);
}
if (lhs.mUserId != rhs.mUserId) {
if (lhs.mUserId == mMyUserId) return -1;
if (rhs.mUserId == mMyUserId) return 1;
return lhs.mUserId < rhs.mUserId ? -1 : 1;
}
if (lhs.mProcess == rhs.mProcess) {
if (lhs.mLabel == rhs.mLabel) {
final Comparator<RunningState.MergedItem> mBackgroundComparator =
new Comparator<RunningState.MergedItem>() {
@Override
public int compare(MergedItem lhs, MergedItem rhs) {
if (DEBUG_COMPARE) {
Log.i(TAG, "Comparing " + lhs + " with " + rhs);
Log.i(TAG, " Proc " + lhs.mProcess + " with " + rhs.mProcess);
Log.i(TAG, " UserId " + lhs.mUserId + " with " + rhs.mUserId);
}
if (lhs.mUserId != rhs.mUserId) {
if (lhs.mUserId == mMyUserId) return -1;
if (rhs.mUserId == mMyUserId) return 1;
return lhs.mUserId < rhs.mUserId ? -1 : 1;
}
if (lhs.mProcess == rhs.mProcess) {
if (lhs.mLabel == rhs.mLabel) {
return 0;
}
return lhs.mLabel != null ? lhs.mLabel.compareTo(rhs.mLabel) : -1;
}
if (lhs.mProcess == null) return -1;
if (rhs.mProcess == null) return 1;
if (DEBUG_COMPARE) {
Log.i(TAG, " Label " + lhs.mProcess.mLabel
+ " with " + rhs.mProcess.mLabel);
}
final ActivityManager.RunningAppProcessInfo lhsInfo =
lhs.mProcess.mRunningProcessInfo;
final ActivityManager.RunningAppProcessInfo rhsInfo =
rhs.mProcess.mRunningProcessInfo;
final boolean lhsBg = lhsInfo.importance
>= ActivityManager.RunningAppProcessInfo.IMPORTANCE_BACKGROUND;
final boolean rhsBg = rhsInfo.importance
>= ActivityManager.RunningAppProcessInfo.IMPORTANCE_BACKGROUND;
if (DEBUG_COMPARE) Log.i(TAG, " Bg " + lhsBg + " with " + rhsBg);
if (lhsBg != rhsBg) {
return lhsBg ? 1 : -1;
}
final boolean lhsA = (lhsInfo.flags
& ActivityManager.RunningAppProcessInfo.FLAG_HAS_ACTIVITIES) != 0;
final boolean rhsA = (rhsInfo.flags
& ActivityManager.RunningAppProcessInfo.FLAG_HAS_ACTIVITIES) != 0;
if (DEBUG_COMPARE) Log.i(TAG, " Act " + lhsA + " with " + rhsA);
if (lhsA != rhsA) {
return lhsA ? -1 : 1;
}
if (DEBUG_COMPARE) {
Log.i(TAG,
" Lru " + lhsInfo.lru + " with " + rhsInfo.lru);
}
if (lhsInfo.lru != rhsInfo.lru) {
return lhsInfo.lru < rhsInfo.lru ? -1 : 1;
}
if (lhs.mProcess.mLabel == rhs.mProcess.mLabel) {
return 0;
}
return lhs.mLabel != null ? lhs.mLabel.compareTo(rhs.mLabel) : -1;
if (lhs.mProcess.mLabel == null) return 1;
if (rhs.mProcess.mLabel == null) return -1;
return lhs.mProcess.mLabel.compareTo(rhs.mProcess.mLabel);
}
if (lhs.mProcess == null) return -1;
if (rhs.mProcess == null) return 1;
if (DEBUG_COMPARE) Log.i(TAG, " Label " + lhs.mProcess.mLabel
+ " with " + rhs.mProcess.mLabel);
final ActivityManager.RunningAppProcessInfo lhsInfo
= lhs.mProcess.mRunningProcessInfo;
final ActivityManager.RunningAppProcessInfo rhsInfo
= rhs.mProcess.mRunningProcessInfo;
final boolean lhsBg = lhsInfo.importance
>= ActivityManager.RunningAppProcessInfo.IMPORTANCE_BACKGROUND;
final boolean rhsBg = rhsInfo.importance
>= ActivityManager.RunningAppProcessInfo.IMPORTANCE_BACKGROUND;
if (DEBUG_COMPARE) Log.i(TAG, " Bg " + lhsBg + " with " + rhsBg);
if (lhsBg != rhsBg) {
return lhsBg ? 1 : -1;
}
final boolean lhsA = (lhsInfo.flags
& ActivityManager.RunningAppProcessInfo.FLAG_HAS_ACTIVITIES) != 0;
final boolean rhsA = (rhsInfo.flags
& ActivityManager.RunningAppProcessInfo.FLAG_HAS_ACTIVITIES) != 0;
if (DEBUG_COMPARE) Log.i(TAG, " Act " + lhsA + " with " + rhsA);
if (lhsA != rhsA) {
return lhsA ? -1 : 1;
}
if (DEBUG_COMPARE) Log.i(TAG, " Lru " + lhsInfo.lru + " with " + rhsInfo.lru);
if (lhsInfo.lru != rhsInfo.lru) {
return lhsInfo.lru < rhsInfo.lru ? -1 : 1;
}
if (lhs.mProcess.mLabel == rhs.mProcess.mLabel) {
return 0;
}
if (lhs.mProcess.mLabel == null) return 1;
if (rhs.mProcess.mLabel == null) return -1;
return lhs.mProcess.mLabel.compareTo(rhs.mProcess.mLabel);
}
};
};
// ----- following protected by mLock -----
@@ -221,6 +226,7 @@ public class RunningState {
// ----- BACKGROUND MONITORING THREAD -----
final HandlerThread mBackgroundThread;
final class BackgroundHandler extends Handler {
public BackgroundHandler(Looper looper) {
super(looper);
@@ -553,7 +559,7 @@ public class RunningState {
if (mCurSeq == curSeq) {
String sizeStr = Formatter.formatShortFileSize(
context, mSize);
if (!sizeStr.equals(mSizeStr)){
if (!sizeStr.equals(mSizeStr)) {
mSizeStr = sizeStr;
// We update this on the second tick where we update just
// the text in the current items, so no need to say we
@@ -567,7 +573,7 @@ public class RunningState {
boolean buildDependencyChain(Context context, PackageManager pm, int curSeq) {
final int NP = mDependentProcesses.size();
boolean changed = false;
for (int i=0; i<NP; i++) {
for (int i = 0; i < NP; i++) {
ProcessItem proc = mDependentProcesses.valueAt(i);
if (proc.mClient != this) {
changed = true;
@@ -589,7 +595,7 @@ public class RunningState {
void addDependentProcesses(ArrayList<BaseItem> dest,
ArrayList<ProcessItem> destProc) {
final int NP = mDependentProcesses.size();
for (int i=0; i<NP; i++) {
for (int i = 0; i < NP; i++) {
ProcessItem proc = mDependentProcesses.valueAt(i);
proc.addDependentProcesses(dest, destProc);
dest.add(proc);
@@ -646,7 +652,7 @@ public class RunningState {
int numProcesses = 0;
int numServices = 0;
mActiveSince = -1;
for (int i=0; i<mChildren.size(); i++) {
for (int i = 0; i < mChildren.size(); i++) {
MergedItem child = mChildren.get(i);
numProcesses += child.mLastNumProcesses;
numServices += child.mLastNumServices;
@@ -668,7 +674,7 @@ public class RunningState {
}
mActiveSince = -1;
for (int i=0; i<mServices.size(); i++) {
for (int i = 0; i < mServices.size(); i++) {
ServiceItem si = mServices.get(i);
if (si.mActiveSince >= 0 && mActiveSince < si.mActiveSince) {
mActiveSince = si.mActiveSince;
@@ -682,21 +688,21 @@ public class RunningState {
boolean updateSize(Context context) {
if (mUser != null) {
mSize = 0;
for (int i=0; i<mChildren.size(); i++) {
for (int i = 0; i < mChildren.size(); i++) {
MergedItem child = mChildren.get(i);
child.updateSize(context);
mSize += child.mSize;
}
} else {
mSize = mProcess.mSize;
for (int i=0; i<mOtherProcesses.size(); i++) {
for (int i = 0; i < mOtherProcesses.size(); i++) {
mSize += mOtherProcesses.get(i).mSize;
}
}
String sizeStr = Formatter.formatShortFileSize(
context, mSize);
if (!sizeStr.equals(mSizeStr)){
if (!sizeStr.equals(mSizeStr)) {
mSizeStr = sizeStr;
// We update this on the second tick where we update just
// the text in the current items, so no need to say we
@@ -760,7 +766,7 @@ public class RunningState {
String label = className;
int tail = label.lastIndexOf('.');
if (tail >= 0) {
label = label.substring(tail+1, label.length());
label = label.substring(tail + 1, label.length());
}
return label;
}
@@ -776,9 +782,9 @@ public class RunningState {
private RunningState(Context context) {
mApplicationContext = context.getApplicationContext();
mAm = (ActivityManager)mApplicationContext.getSystemService(Context.ACTIVITY_SERVICE);
mAm = mApplicationContext.getSystemService(ActivityManager.class);
mPm = mApplicationContext.getPackageManager();
mUm = (UserManager)mApplicationContext.getSystemService(Context.USER_SERVICE);
mUm = mApplicationContext.getSystemService(UserManager.class);
mMyUserId = UserHandle.myUserId();
UserInfo userInfo = mUm.getUserInfo(mMyUserId);
mHideManagedProfiles = userInfo == null || !userInfo.canHaveProfile();
@@ -842,14 +848,14 @@ public class RunningState {
}
private boolean isInterestingProcess(ActivityManager.RunningAppProcessInfo pi) {
if ((pi.flags&ActivityManager.RunningAppProcessInfo.FLAG_CANT_SAVE_STATE) != 0) {
if ((pi.flags & ActivityManager.RunningAppProcessInfo.FLAG_CANT_SAVE_STATE) != 0) {
return true;
}
if ((pi.flags&ActivityManager.RunningAppProcessInfo.FLAG_PERSISTENT) == 0
if ((pi.flags & ActivityManager.RunningAppProcessInfo.FLAG_PERSISTENT) == 0
&& pi.importance >= ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND
&& pi.importance < ActivityManager.RunningAppProcessInfo.IMPORTANCE_CANT_SAVE_STATE
&& pi.importanceReasonCode
== ActivityManager.RunningAppProcessInfo.REASON_UNKNOWN) {
== ActivityManager.RunningAppProcessInfo.REASON_UNKNOWN) {
return true;
}
return false;
@@ -905,7 +911,7 @@ public class RunningState {
List<ActivityManager.RunningServiceInfo> services
= am.getRunningServices(MAX_SERVICES);
int NS = services != null ? services.size() : 0;
for (int i=0; i<NS; i++) {
for (int i = 0; i < NS; i++) {
ActivityManager.RunningServiceInfo si = services.get(i);
// We are not interested in services that have not been started
// and don't have a known client, because
@@ -918,7 +924,7 @@ public class RunningState {
}
// We likewise don't care about services running in a
// persistent process like the system or phone.
if ((si.flags&ActivityManager.RunningServiceInfo.FLAG_PERSISTENT_PROCESS)
if ((si.flags & ActivityManager.RunningServiceInfo.FLAG_PERSISTENT_PROCESS)
!= 0) {
services.remove(i);
i--;
@@ -933,14 +939,14 @@ public class RunningState {
= am.getRunningAppProcesses();
final int NP = processes != null ? processes.size() : 0;
mTmpAppProcesses.clear();
for (int i=0; i<NP; i++) {
for (int i = 0; i < NP; i++) {
ActivityManager.RunningAppProcessInfo pi = processes.get(i);
mTmpAppProcesses.put(pi.pid, new AppProcessInfo(pi));
}
// Initial iteration through running services to collect per-process
// info about them.
for (int i=0; i<NS; i++) {
for (int i = 0; i < NS; i++) {
ActivityManager.RunningServiceInfo si = services.get(i);
if (si.restarting == 0 && si.pid > 0) {
AppProcessInfo ainfo = mTmpAppProcesses.get(si.pid);
@@ -954,7 +960,7 @@ public class RunningState {
}
// Update state we are maintaining about process that are running services.
for (int i=0; i<NS; i++) {
for (int i = 0; i < NS; i++) {
ActivityManager.RunningServiceInfo si = services.get(i);
// If this service's process is in use at a higher importance
@@ -1024,7 +1030,7 @@ public class RunningState {
// Now update the map of other processes that are running (but
// don't have services actively running inside them).
for (int i=0; i<NP; i++) {
for (int i = 0; i < NP; i++) {
ActivityManager.RunningAppProcessInfo pi = processes.get(i);
ProcessItem proc = mServiceProcessesByPid.get(pi.pid);
if (proc == null) {
@@ -1060,7 +1066,7 @@ public class RunningState {
// Build the chains from client processes to the process they are
// dependent on; also remove any old running processes.
int NRP = mRunningProcesses.size();
for (int i = 0; i < NRP;) {
for (int i = 0; i < NRP; ) {
ProcessItem proc = mRunningProcesses.valueAt(i);
if (proc.mRunningSeq == mSequence) {
int clientPid = proc.mRunningProcessInfo.importanceReasonPid;
@@ -1088,7 +1094,7 @@ public class RunningState {
// Remove any old interesting processes.
int NHP = mInterestingProcesses.size();
for (int i=0; i<NHP; i++) {
for (int i = 0; i < NHP; i++) {
ProcessItem proc = mInterestingProcesses.get(i);
if (!proc.mInteresting || mRunningProcesses.get(proc.mPid) == null) {
changed = true;
@@ -1102,7 +1108,7 @@ public class RunningState {
// processes they are dependent on, marking these processes as
// still being active and determining if anything has changed.
final int NAP = mServiceProcessesByPid.size();
for (int i=0; i<NAP; i++) {
for (int i = 0; i < NAP; i++) {
ProcessItem proc = mServiceProcessesByPid.valueAt(i);
if (proc.mCurSeq == mSequence) {
changed |= proc.buildDependencyChain(context, pm, mSequence);
@@ -1111,7 +1117,7 @@ public class RunningState {
// Look for services and their primary processes that no longer exist...
ArrayList<Integer> uidToDelete = null;
for (int i=0; i<mServiceProcessesByName.size(); i++) {
for (int i = 0; i < mServiceProcessesByName.size(); i++) {
HashMap<String, ProcessItem> procs = mServiceProcessesByName.valueAt(i);
Iterator<ProcessItem> pit = procs.values().iterator();
while (pit.hasNext()) {
@@ -1119,8 +1125,7 @@ public class RunningState {
if (pi.mCurSeq == mSequence) {
pi.ensureLabel(pm);
if (pi.mPid == 0) {
// Sanity: a non-process can't be dependent on
// anything.
// Validation: a non-process can't be dependent on anything.
pi.mDependentProcesses.clear();
}
} else {
@@ -1158,7 +1163,7 @@ public class RunningState {
if (changed) {
// First determine an order for the services.
ArrayList<ProcessItem> sortedProcesses = new ArrayList<ProcessItem>();
for (int i=0; i<mServiceProcessesByName.size(); i++) {
for (int i = 0; i < mServiceProcessesByName.size(); i++) {
for (ProcessItem pi : mServiceProcessesByName.valueAt(i).values()) {
pi.mIsSystem = false;
pi.mIsStarted = true;
@@ -1166,7 +1171,7 @@ public class RunningState {
for (ServiceItem si : pi.mServices.values()) {
if (si.mServiceInfo != null
&& (si.mServiceInfo.applicationInfo.flags
& ApplicationInfo.FLAG_SYSTEM) != 0) {
& ApplicationInfo.FLAG_SYSTEM) != 0) {
pi.mIsSystem = true;
}
if (si.mRunningService != null
@@ -1186,7 +1191,7 @@ public class RunningState {
ArrayList<BaseItem> newItems = new ArrayList<BaseItem>();
ArrayList<MergedItem> newMergedItems = new ArrayList<MergedItem>();
mProcessItems.clear();
for (int i=0; i<sortedProcesses.size(); i++) {
for (int i = 0; i < sortedProcesses.size(); i++) {
ProcessItem pi = sortedProcesses.get(i);
pi.mNeedDivider = false;
@@ -1227,7 +1232,7 @@ public class RunningState {
}
mergedItem.mProcess = pi;
mergedItem.mOtherProcesses.clear();
for (int mpi=firstProc; mpi<(mProcessItems.size()-1); mpi++) {
for (int mpi = firstProc; mpi < (mProcessItems.size() - 1); mpi++) {
mergedItem.mOtherProcesses.add(mProcessItems.get(mpi));
}
}
@@ -1243,7 +1248,7 @@ public class RunningState {
// Finally, interesting processes need to be shown and will
// go at the top.
NHP = mInterestingProcesses.size();
for (int i=0; i<NHP; i++) {
for (int i = 0; i < NHP; i++) {
ProcessItem proc = mInterestingProcesses.get(i);
if (proc.mClient == null && proc.mServices.size() <= 0) {
if (proc.mMergedItem == null) {
@@ -1264,7 +1269,7 @@ public class RunningState {
// Finally finally, user aggregated merged items need to be
// updated now that they have all of their children.
final int NU = mOtherUserMergedItems.size();
for (int i=0; i<NU; i++) {
for (int i = 0; i < NU; i++) {
MergedItem user = mOtherUserMergedItems.valueAt(i);
if (user.mCurSeq == mSequence) {
user.update(context, false);
@@ -1285,7 +1290,7 @@ public class RunningState {
int numForegroundProcesses = 0;
int numServiceProcesses = 0;
NRP = mRunningProcesses.size();
for (int i=0; i<NRP; i++) {
for (int i = 0; i < NRP; i++) {
ProcessItem proc = mRunningProcesses.valueAt(i);
if (proc.mCurSeq != mSequence) {
// We didn't hit this process as a dependency on one
@@ -1316,13 +1321,13 @@ public class RunningState {
try {
final int numProc = mAllProcessItems.size();
int[] pids = new int[numProc];
for (int i=0; i<numProc; i++) {
for (int i = 0; i < numProc; i++) {
pids[i] = mAllProcessItems.get(i).mPid;
}
long[] pss = ActivityManager.getService()
.getProcessPss(pids);
int bgIndex = 0;
for (int i=0; i<pids.length; i++) {
for (int i = 0; i < pids.length; i++) {
ProcessItem proc = mAllProcessItems.get(i);
changed |= proc.updateSize(context, pss[i], mSequence);
if (proc.mCurSeq == mSequence) {
@@ -1340,7 +1345,7 @@ public class RunningState {
if (bgIndex >= mBackgroundItems.size()
|| mBackgroundItems.get(bgIndex).mProcess != proc) {
newBackgroundItems = new ArrayList<MergedItem>(numBackgroundProcesses);
for (int bgi=0; bgi<bgIndex; bgi++) {
for (int bgi = 0; bgi < bgIndex; bgi++) {
mergedItem = mBackgroundItems.get(bgi);
diffUsers |= mergedItem.mUserId != mMyUserId;
newBackgroundItems.add(mergedItem);
@@ -1368,7 +1373,7 @@ public class RunningState {
// One or more at the bottom may no longer exist.
if (mBackgroundItems.size() > numBackgroundProcesses) {
newBackgroundItems = new ArrayList<MergedItem>(numBackgroundProcesses);
for (int bgi=0; bgi<numBackgroundProcesses; bgi++) {
for (int bgi = 0; bgi < numBackgroundProcesses; bgi++) {
MergedItem mergedItem = mBackgroundItems.get(bgi);
diffUsers |= mergedItem.mUserId != mMyUserId;
newBackgroundItems.add(mergedItem);
@@ -1387,7 +1392,7 @@ public class RunningState {
// items for users are collapsed together.
newUserBackgroundItems = new ArrayList<MergedItem>();
final int NB = newBackgroundItems.size();
for (int i=0; i<NB; i++) {
for (int i = 0; i < NB; i++) {
MergedItem mergedItem = newBackgroundItems.get(i);
if (mergedItem.mUserId != mMyUserId) {
addOtherUserItem(context, newUserBackgroundItems,
@@ -1399,7 +1404,7 @@ public class RunningState {
// And user aggregated merged items need to be
// updated now that they have all of their children.
final int NU = mOtherUserBackgroundItems.size();
for (int i=0; i<NU; i++) {
for (int i = 0; i < NU; i++) {
MergedItem user = mOtherUserBackgroundItems.valueAt(i);
if (user.mCurSeq == mSequence) {
user.update(context, true);
@@ -1409,7 +1414,7 @@ public class RunningState {
}
}
for (int i=0; i<mMergedItems.size(); i++) {
for (int i = 0; i < mMergedItems.size(); i++) {
mMergedItems.get(i).updateSize(context);
}

View File

@@ -112,7 +112,7 @@ public class BatteryTipPreferenceController extends BasePreferenceController {
for (int i = 0, size = batteryTips.size(); i < size; i++) {
final BatteryTip batteryTip = mBatteryTips.get(i);
batteryTip.sanityCheck(mContext);
batteryTip.validateCheck(mContext);
if (batteryTip.getState() != BatteryTip.StateType.INVISIBLE) {
batteryTip.updatePreference(mCardPreference);
mBatteryTipMap.put(mCardPreference.getKey(), batteryTip);

View File

@@ -138,7 +138,7 @@ public abstract class BatteryTip implements Comparable<BatteryTip>, Parcelable {
* Check whether data is still make sense. If not, try recover.
* @param context used to do validate check
*/
public void sanityCheck(Context context) {
public void validateCheck(Context context) {
// do nothing
}

View File

@@ -107,8 +107,8 @@ public class RestrictAppTip extends BatteryTip {
}
@Override
public void sanityCheck(Context context) {
super.sanityCheck(context);
public void validateCheck(Context context) {
super.validateCheck(context);
// Set it invisible if there is no valid app
mRestrictAppList.removeIf(AppLabelPredicate.getInstance(context));

View File

@@ -34,7 +34,6 @@ import android.os.Parcel;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
import com.android.settings.fuelgauge.batterytip.AppInfo;
import com.android.settings.testutils.BatteryTestUtils;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
import org.junit.After;
@@ -45,10 +44,10 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.util.ReflectionHelpers;
import java.util.ArrayList;
import java.util.List;
import org.robolectric.util.ReflectionHelpers;
@RunWith(RobolectricTestRunner.class)
public class RestrictAppTipTest {
@@ -198,7 +197,7 @@ public class RestrictAppTipTest {
appInfos.add(mUninstallAppInfo);
final BatteryTip batteryTip = new RestrictAppTip(BatteryTip.StateType.NEW, appInfos);
batteryTip.sanityCheck(mContext);
batteryTip.validateCheck(mContext);
assertThat(batteryTip.getState()).isEqualTo(BatteryTip.StateType.INVISIBLE);
}
@@ -210,7 +209,7 @@ public class RestrictAppTipTest {
appInfos.add(mUninstallAppInfo);
final BatteryTip batteryTip = new RestrictAppTip(BatteryTip.StateType.NEW, appInfos);
batteryTip.sanityCheck(mContext);
batteryTip.validateCheck(mContext);
assertThat(batteryTip.getState()).isEqualTo(BatteryTip.StateType.NEW);
}