Merge "Moves icon management to NotificationRowBinder."
diff --git a/Android.bp b/Android.bp
index cd0720d..eb9cbbb 100644
--- a/Android.bp
+++ b/Android.bp
@@ -269,7 +269,7 @@
"core/java/android/os/storage/IStorageEventListener.aidl",
"core/java/android/os/storage/IStorageShutdownObserver.aidl",
"core/java/android/os/storage/IObbActionListener.aidl",
- "core/java/android/permission/IRuntimePermissionPresenter.aidl",
+ "core/java/android/permission/IPermissionController.aidl",
"core/java/android/rolecontrollerservice/IRoleControllerService.aidl",
":keystore_aidl",
"core/java/android/security/keymaster/IKeyAttestationApplicationIdProvider.aidl",
diff --git a/api/current.txt b/api/current.txt
index fad607c..29d459e 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -11598,8 +11598,11 @@
field public static final java.lang.String FEATURE_MICROPHONE = "android.hardware.microphone";
field public static final java.lang.String FEATURE_MIDI = "android.software.midi";
field public static final java.lang.String FEATURE_NFC = "android.hardware.nfc";
+ field public static final java.lang.String FEATURE_NFC_BEAM = "android.sofware.nfc.beam";
field public static final java.lang.String FEATURE_NFC_HOST_CARD_EMULATION = "android.hardware.nfc.hce";
field public static final java.lang.String FEATURE_NFC_HOST_CARD_EMULATION_NFCF = "android.hardware.nfc.hcef";
+ field public static final java.lang.String FEATURE_NFC_OFF_HOST_CARD_EMULATION_ESE = "android.hardware.nfc.ese";
+ field public static final java.lang.String FEATURE_NFC_OFF_HOST_CARD_EMULATION_UICC = "android.hardware.nfc.uicc";
field public static final java.lang.String FEATURE_OPENGLES_EXTENSION_PACK = "android.hardware.opengles.aep";
field public static final java.lang.String FEATURE_PC = "android.hardware.type.pc";
field public static final java.lang.String FEATURE_PICTURE_IN_PICTURE = "android.software.picture_in_picture";
@@ -29751,7 +29754,10 @@
method public void onIdentityChanged(byte[]);
}
- public class PeerHandle {
+ public final class PeerHandle implements android.os.Parcelable {
+ method public int describeContents();
+ method public void writeToParcel(android.os.Parcel, int);
+ field public static final android.os.Parcelable.Creator<android.net.wifi.aware.PeerHandle> CREATOR;
}
public final class PublishConfig implements android.os.Parcelable {
@@ -30286,15 +30292,16 @@
method public deprecated void enableForegroundNdefPush(android.app.Activity, android.nfc.NdefMessage);
method public void enableReaderMode(android.app.Activity, android.nfc.NfcAdapter.ReaderCallback, int, android.os.Bundle);
method public static android.nfc.NfcAdapter getDefaultAdapter(android.content.Context);
+ method public java.util.List<java.lang.String> getSupportedOffHostSecureElements();
method public boolean ignore(android.nfc.Tag, int, android.nfc.NfcAdapter.OnTagRemovedListener, android.os.Handler);
- method public boolean invokeBeam(android.app.Activity);
+ method public deprecated boolean invokeBeam(android.app.Activity);
method public boolean isEnabled();
- method public boolean isNdefPushEnabled();
- method public void setBeamPushUris(android.net.Uri[], android.app.Activity);
- method public void setBeamPushUrisCallback(android.nfc.NfcAdapter.CreateBeamUrisCallback, android.app.Activity);
- method public void setNdefPushMessage(android.nfc.NdefMessage, android.app.Activity, android.app.Activity...);
- method public void setNdefPushMessageCallback(android.nfc.NfcAdapter.CreateNdefMessageCallback, android.app.Activity, android.app.Activity...);
- method public void setOnNdefPushCompleteCallback(android.nfc.NfcAdapter.OnNdefPushCompleteCallback, android.app.Activity, android.app.Activity...);
+ method public deprecated boolean isNdefPushEnabled();
+ method public deprecated void setBeamPushUris(android.net.Uri[], android.app.Activity);
+ method public deprecated void setBeamPushUrisCallback(android.nfc.NfcAdapter.CreateBeamUrisCallback, android.app.Activity);
+ method public deprecated void setNdefPushMessage(android.nfc.NdefMessage, android.app.Activity, android.app.Activity...);
+ method public deprecated void setNdefPushMessageCallback(android.nfc.NfcAdapter.CreateNdefMessageCallback, android.app.Activity, android.app.Activity...);
+ method public deprecated void setOnNdefPushCompleteCallback(android.nfc.NfcAdapter.OnNdefPushCompleteCallback, android.app.Activity, android.app.Activity...);
field public static final java.lang.String ACTION_ADAPTER_STATE_CHANGED = "android.nfc.action.ADAPTER_STATE_CHANGED";
field public static final java.lang.String ACTION_NDEF_DISCOVERED = "android.nfc.action.NDEF_DISCOVERED";
field public static final java.lang.String ACTION_TAG_DISCOVERED = "android.nfc.action.TAG_DISCOVERED";
@@ -30321,15 +30328,15 @@
field public static final int STATE_TURNING_ON = 2; // 0x2
}
- public static abstract interface NfcAdapter.CreateBeamUrisCallback {
+ public static abstract deprecated interface NfcAdapter.CreateBeamUrisCallback {
method public abstract android.net.Uri[] createBeamUris(android.nfc.NfcEvent);
}
- public static abstract interface NfcAdapter.CreateNdefMessageCallback {
+ public static abstract deprecated interface NfcAdapter.CreateNdefMessageCallback {
method public abstract android.nfc.NdefMessage createNdefMessage(android.nfc.NfcEvent);
}
- public static abstract interface NfcAdapter.OnNdefPushCompleteCallback {
+ public static abstract deprecated interface NfcAdapter.OnNdefPushCompleteCallback {
method public abstract void onNdefPushComplete(android.nfc.NfcEvent);
}
@@ -30377,8 +30384,10 @@
method public boolean isDefaultServiceForCategory(android.content.ComponentName, java.lang.String);
method public boolean registerAidsForService(android.content.ComponentName, java.lang.String, java.util.List<java.lang.String>);
method public boolean removeAidsForService(android.content.ComponentName, java.lang.String);
+ method public boolean setOffHostForService(android.content.ComponentName, java.lang.String);
method public boolean setPreferredService(android.app.Activity, android.content.ComponentName);
method public boolean supportsAidPrefixRegistration();
+ method public boolean unsetOffHostForService(android.content.ComponentName);
method public boolean unsetPreferredService(android.app.Activity);
field public static final java.lang.String ACTION_CHANGE_DEFAULT = "android.nfc.cardemulation.action.ACTION_CHANGE_DEFAULT";
field public static final java.lang.String CATEGORY_OTHER = "other";
diff --git a/api/system-current.txt b/api/system-current.txt
index 01304a6..05aa0ad 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -62,6 +62,7 @@
field public static final java.lang.String FORCE_STOP_PACKAGES = "android.permission.FORCE_STOP_PACKAGES";
field public static final java.lang.String GET_APP_OPS_STATS = "android.permission.GET_APP_OPS_STATS";
field public static final java.lang.String GET_PROCESS_STATE_AND_OOM_SCORE = "android.permission.GET_PROCESS_STATE_AND_OOM_SCORE";
+ field public static final java.lang.String GET_RUNTIME_PERMISSIONS = "android.permission.GET_RUNTIME_PERMISSIONS";
field public static final java.lang.String GET_TOP_ACTIVITY_INFO = "android.permission.GET_TOP_ACTIVITY_INFO";
field public static final java.lang.String GRANT_PROFILE_OWNER_DEVICE_IDS_ACCESS = "android.permission.GRANT_PROFILE_OWNER_DEVICE_IDS_ACCESS";
field public static final java.lang.String GRANT_RUNTIME_PERMISSIONS = "android.permission.GRANT_RUNTIME_PERMISSIONS";
@@ -1511,8 +1512,6 @@
public final class BrightnessConfiguration implements android.os.Parcelable {
method public int describeContents();
- method public android.hardware.display.BrightnessCorrection getCorrectionByCategory(int);
- method public android.hardware.display.BrightnessCorrection getCorrectionByPackageName(java.lang.String);
method public android.util.Pair<float[], float[]> getCurve();
method public void writeToParcel(android.os.Parcel, int);
field public static final android.os.Parcelable.Creator<android.hardware.display.BrightnessConfiguration> CREATOR;
@@ -1520,22 +1519,10 @@
public static class BrightnessConfiguration.Builder {
ctor public BrightnessConfiguration.Builder(float[], float[]);
- method public android.hardware.display.BrightnessConfiguration.Builder addCorrectionByCategory(int, android.hardware.display.BrightnessCorrection);
- method public android.hardware.display.BrightnessConfiguration.Builder addCorrectionByPackageName(java.lang.String, android.hardware.display.BrightnessCorrection);
method public android.hardware.display.BrightnessConfiguration build();
- method public int getMaxCorrectionsByCategory();
- method public int getMaxCorrectionsByPackageName();
method public android.hardware.display.BrightnessConfiguration.Builder setDescription(java.lang.String);
}
- public final class BrightnessCorrection implements android.os.Parcelable {
- method public float apply(float);
- method public static android.hardware.display.BrightnessCorrection createScaleAndTranslateLog(float, float);
- method public int describeContents();
- method public void writeToParcel(android.os.Parcel, int);
- field public static final android.os.Parcelable.Creator<android.hardware.display.BrightnessCorrection> CREATOR;
- }
-
public final class DisplayManager {
method public java.util.List<android.hardware.display.AmbientBrightnessDayStats> getAmbientBrightnessStats();
method public android.hardware.display.BrightnessConfiguration getBrightnessConfiguration();
@@ -4608,6 +4595,16 @@
package android.permission {
+ public abstract class PermissionControllerService extends android.app.Service {
+ ctor public PermissionControllerService();
+ method public final void attachBaseContext(android.content.Context);
+ method public final android.os.IBinder onBind(android.content.Intent);
+ method public abstract int onCountPermissionApps(java.util.List<java.lang.String>, boolean, boolean);
+ method public abstract java.util.List<android.permission.RuntimePermissionPresentationInfo> onGetAppPermissions(java.lang.String);
+ method public abstract void onRevokeRuntimePermission(java.lang.String, java.lang.String);
+ field public static final java.lang.String SERVICE_INTERFACE = "android.permission.PermissionControllerService";
+ }
+
public final class PermissionManager {
method public java.util.List<android.permission.PermissionManager.SplitPermissionInfo> getSplitPermissions();
}
@@ -4628,16 +4625,6 @@
field public static final android.os.Parcelable.Creator<android.permission.RuntimePermissionPresentationInfo> CREATOR;
}
- public abstract class RuntimePermissionPresenterService extends android.app.Service {
- ctor public RuntimePermissionPresenterService();
- method public final void attachBaseContext(android.content.Context);
- method public final android.os.IBinder onBind(android.content.Intent);
- method public abstract int onCountPermissionApps(java.util.List<java.lang.String>, boolean, boolean);
- method public abstract java.util.List<android.permission.RuntimePermissionPresentationInfo> onGetAppPermissions(java.lang.String);
- method public abstract void onRevokeRuntimePermission(java.lang.String, java.lang.String);
- field public static final java.lang.String SERVICE_INTERFACE = "android.permission.RuntimePermissionPresenterService";
- }
-
}
package android.permissionpresenterservice {
diff --git a/cmds/statsd/Android.bp b/cmds/statsd/Android.bp
index d610f66..59b2aa6 100644
--- a/cmds/statsd/Android.bp
+++ b/cmds/statsd/Android.bp
@@ -332,6 +332,8 @@
"src/stats_log.proto",
"src/statsd_config.proto",
"src/atoms.proto",
+ "src/shell/shell_config.proto",
+ "src/shell/shell_data.proto",
],
static_libs: [
diff --git a/cmds/statsd/src/StatsService.cpp b/cmds/statsd/src/StatsService.cpp
index f2a4663..3107b4d 100644
--- a/cmds/statsd/src/StatsService.cpp
+++ b/cmds/statsd/src/StatsService.cpp
@@ -360,7 +360,11 @@
if (mShellSubscriber == nullptr) {
mShellSubscriber = new ShellSubscriber(mUidMap, mPullerManager);
}
- mShellSubscriber->startNewSubscription(in, out, resultReceiver);
+ int timeoutSec = -1;
+ if (argCount >= 2) {
+ timeoutSec = atoi(args[1].c_str());
+ }
+ mShellSubscriber->startNewSubscription(in, out, resultReceiver, timeoutSec);
return NO_ERROR;
}
}
diff --git a/cmds/statsd/src/shell/ShellSubscriber.cpp b/cmds/statsd/src/shell/ShellSubscriber.cpp
index 22883f3..52d5ffc 100644
--- a/cmds/statsd/src/shell/ShellSubscriber.cpp
+++ b/cmds/statsd/src/shell/ShellSubscriber.cpp
@@ -30,7 +30,8 @@
const static int FIELD_ID_ATOM = 1;
-void ShellSubscriber::startNewSubscription(int in, int out, sp<IResultReceiver> resultReceiver) {
+void ShellSubscriber::startNewSubscription(int in, int out, sp<IResultReceiver> resultReceiver,
+ int timeoutSec) {
VLOG("start new shell subscription");
{
std::lock_guard<std::mutex> lock(mMutex);
@@ -50,11 +51,18 @@
// Read config forever until EOF is reached. Clients may send multiple configs -- each new
// config replace the previous one.
readConfig(in);
+ VLOG("timeout : %d", timeoutSec);
// Now we have read an EOF we now wait for the semaphore until the client exits.
VLOG("Now wait for client to exit");
std::unique_lock<std::mutex> lk(mMutex);
- mShellDied.wait(lk, [this, resultReceiver] { return mResultReceiver != resultReceiver; });
+
+ if (timeoutSec > 0) {
+ mShellDied.wait_for(lk, timeoutSec * 1s,
+ [this, resultReceiver] { return mResultReceiver != resultReceiver; });
+ } else {
+ mShellDied.wait(lk, [this, resultReceiver] { return mResultReceiver != resultReceiver; });
+ }
}
void ShellSubscriber::updateConfig(const ShellSubscription& config) {
diff --git a/cmds/statsd/src/shell/ShellSubscriber.h b/cmds/statsd/src/shell/ShellSubscriber.h
index 5401f31..8e54a8b 100644
--- a/cmds/statsd/src/shell/ShellSubscriber.h
+++ b/cmds/statsd/src/shell/ShellSubscriber.h
@@ -65,7 +65,8 @@
/**
* Start a new subscription.
*/
- void startNewSubscription(int inFd, int outFd, sp<IResultReceiver> resultReceiver);
+ void startNewSubscription(int inFd, int outFd, sp<IResultReceiver> resultReceiver,
+ int timeoutSec);
void binderDied(const wp<IBinder>& who);
diff --git a/cmds/statsd/tests/shell/ShellSubscriber_test.cpp b/cmds/statsd/tests/shell/ShellSubscriber_test.cpp
index a184f56..73d1fd7 100644
--- a/cmds/statsd/tests/shell/ShellSubscriber_test.cpp
+++ b/cmds/statsd/tests/shell/ShellSubscriber_test.cpp
@@ -83,7 +83,7 @@
// mimic a binder thread that a shell subscriber runs on. it would block.
std::thread reader([&resultReceiver, &fds_config, &fds_data, &shellClient] {
- shellClient->startNewSubscription(fds_config[0], fds_data[1], resultReceiver);
+ shellClient->startNewSubscription(fds_config[0], fds_data[1], resultReceiver, -1);
});
reader.detach();
diff --git a/cmds/statsd/tools/localtools/src/com/android/statsd/shelltools/testdrive/TestDrive.java b/cmds/statsd/tools/localtools/src/com/android/statsd/shelltools/testdrive/TestDrive.java
index 0775afe..de818a8 100644
--- a/cmds/statsd/tools/localtools/src/com/android/statsd/shelltools/testdrive/TestDrive.java
+++ b/cmds/statsd/tools/localtools/src/com/android/statsd/shelltools/testdrive/TestDrive.java
@@ -54,7 +54,8 @@
"AID_SYSTEM",
"AID_ROOT",
"AID_BLUETOOTH",
- "AID_LMKD"
+ "AID_LMKD",
+ "com.android.managedprovisioning"
};
private static final Logger LOGGER = Logger.getLogger(TestDrive.class.getName());
diff --git a/core/java/android/app/SystemServiceRegistry.java b/core/java/android/app/SystemServiceRegistry.java
index 3f6ebc8..9ddf4bd 100644
--- a/core/java/android/app/SystemServiceRegistry.java
+++ b/core/java/android/app/SystemServiceRegistry.java
@@ -144,6 +144,7 @@
import android.os.Vibrator;
import android.os.health.SystemHealthManager;
import android.os.storage.StorageManager;
+import android.permission.PermissionControllerManager;
import android.permission.PermissionManager;
import android.print.IPrintManager;
import android.print.PrintManager;
@@ -1164,6 +1165,13 @@
return new PermissionManager(ctx.getOuterContext());
}});
+ registerService(Context.PERMISSION_CONTROLLER_SERVICE, PermissionControllerManager.class,
+ new CachedServiceFetcher<PermissionControllerManager>() {
+ @Override
+ public PermissionControllerManager createService(ContextImpl ctx) {
+ return new PermissionControllerManager(ctx.getOuterContext());
+ }});
+
registerService(Context.ROLE_SERVICE, RoleManager.class,
new CachedServiceFetcher<RoleManager>() {
@Override
diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java
index f843262..7da67d9 100644
--- a/core/java/android/app/admin/DevicePolicyManager.java
+++ b/core/java/android/app/admin/DevicePolicyManager.java
@@ -907,9 +907,8 @@
= "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER";
/**
- * A String extra holding the URL-safe base64 encoded SHA-256 or SHA-1 hash (see notes below) of
- * the file at download location specified in
- * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
+ * A String extra holding the URL-safe base64 encoded SHA-256 hash of the file at download
+ * location specified in {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}.
*
* <p>Either this extra or {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM} must be
* present. The provided checksum must match the checksum of the file at the download
@@ -922,7 +921,8 @@
* <p><strong>Note:</strong> for devices running {@link android.os.Build.VERSION_CODES#LOLLIPOP}
* and {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1} only SHA-1 hash is supported.
* Starting from {@link android.os.Build.VERSION_CODES#M}, this parameter accepts SHA-256 in
- * addition to SHA-1. Support for SHA-1 is likely to be removed in future OS releases.
+ * addition to SHA-1. From {@link android.os.Build.VERSION_CODES#Q}, only SHA-256 hash is
+ * supported.
*/
public static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM
= "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM";
diff --git a/core/java/android/content/Context.java b/core/java/android/content/Context.java
index 0aa6a8c..eb7be6f 100644
--- a/core/java/android/content/Context.java
+++ b/core/java/android/content/Context.java
@@ -3993,6 +3993,14 @@
public static final String PERMISSION_SERVICE = "permission";
/**
+ * Official published name of the (internal) permission controller service.
+ *
+ * @see #getSystemService(String)
+ * @hide
+ */
+ public static final String PERMISSION_CONTROLLER_SERVICE = "permission_controller";
+
+ /**
* Use with {@link #getSystemService(String)} to retrieve an
* {@link android.app.backup.IBackupManager IBackupManager} for communicating
* with the backup mechanism.
diff --git a/core/java/android/content/pm/PackageManager.java b/core/java/android/content/pm/PackageManager.java
index 6110557..2aeb68d 100644
--- a/core/java/android/content/pm/PackageManager.java
+++ b/core/java/android/content/pm/PackageManager.java
@@ -1368,6 +1368,14 @@
*/
public static final int INSTALL_FAILED_BAD_DEX_METADATA = -117;
+ /**
+ * Installation parse return code: this is passed in the
+ * {@link PackageInstaller#EXTRA_LEGACY_STATUS} if there is any signature problem.
+ *
+ * @hide
+ */
+ public static final int INSTALL_FAILED_BAD_SIGNATURE = -118;
+
/** @hide */
@IntDef(flag = true, prefix = { "DELETE_" }, value = {
DELETE_KEEP_DATA,
@@ -1931,6 +1939,30 @@
/**
* Feature for {@link #getSystemAvailableFeatures} and
+ * {@link #hasSystemFeature}: The device supports uicc-
+ * based NFC card emulation.
+ */
+ @SdkConstant(SdkConstantType.FEATURE)
+ public static final String FEATURE_NFC_OFF_HOST_CARD_EMULATION_UICC =
+ "android.hardware.nfc.uicc";
+
+ /**
+ * Feature for {@link #getSystemAvailableFeatures} and
+ * {@link #hasSystemFeature}: The device supports eSE-
+ * based NFC card emulation.
+ */
+ @SdkConstant(SdkConstantType.FEATURE)
+ public static final String FEATURE_NFC_OFF_HOST_CARD_EMULATION_ESE = "android.hardware.nfc.ese";
+
+ /**
+ * Feature for {@link #getSystemAvailableFeatures} and
+ * {@link #hasSystemFeature}: The Beam API is enabled on the device.
+ */
+ @SdkConstant(SdkConstantType.FEATURE)
+ public static final String FEATURE_NFC_BEAM = "android.sofware.nfc.beam";
+
+ /**
+ * Feature for {@link #getSystemAvailableFeatures} and
* {@link #hasSystemFeature}: The device supports any
* one of the {@link #FEATURE_NFC}, {@link #FEATURE_NFC_HOST_CARD_EMULATION},
* or {@link #FEATURE_NFC_HOST_CARD_EMULATION_NFCF} features.
@@ -6243,6 +6275,7 @@
case INSTALL_FAILED_ABORTED: return "INSTALL_FAILED_ABORTED";
case INSTALL_FAILED_BAD_DEX_METADATA: return "INSTALL_FAILED_BAD_DEX_METADATA";
case INSTALL_FAILED_MISSING_SPLIT: return "INSTALL_FAILED_MISSING_SPLIT";
+ case INSTALL_FAILED_BAD_SIGNATURE: return "INSTALL_FAILED_BAD_SIGNATURE";
default: return Integer.toString(status);
}
}
@@ -6288,6 +6321,7 @@
case INSTALL_PARSE_FAILED_MANIFEST_MALFORMED: return PackageInstaller.STATUS_FAILURE_INVALID;
case INSTALL_PARSE_FAILED_MANIFEST_EMPTY: return PackageInstaller.STATUS_FAILURE_INVALID;
case INSTALL_FAILED_BAD_DEX_METADATA: return PackageInstaller.STATUS_FAILURE_INVALID;
+ case INSTALL_FAILED_BAD_SIGNATURE: return PackageInstaller.STATUS_FAILURE_INVALID;
case INSTALL_FAILED_INTERNAL_ERROR: return PackageInstaller.STATUS_FAILURE;
case INSTALL_FAILED_USER_RESTRICTED: return PackageInstaller.STATUS_FAILURE_INCOMPATIBLE;
case INSTALL_FAILED_DUPLICATE_PERMISSION: return PackageInstaller.STATUS_FAILURE_CONFLICT;
diff --git a/core/java/android/hardware/display/BrightnessConfiguration.java b/core/java/android/hardware/display/BrightnessConfiguration.java
index be054297..7e52ca3 100644
--- a/core/java/android/hardware/display/BrightnessConfiguration.java
+++ b/core/java/android/hardware/display/BrightnessConfiguration.java
@@ -19,54 +19,26 @@
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.annotation.TestApi;
-import android.content.pm.ApplicationInfo;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.Pair;
import com.android.internal.util.Preconditions;
-import com.android.internal.util.XmlUtils;
-import org.xmlpull.v1.XmlPullParser;
-import org.xmlpull.v1.XmlPullParserException;
-import org.xmlpull.v1.XmlSerializer;
-
-import java.io.IOException;
-import java.util.ArrayList;
import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
import java.util.Objects;
/** @hide */
@SystemApi
@TestApi
public final class BrightnessConfiguration implements Parcelable {
- private static final String TAG_BRIGHTNESS_CURVE = "brightness-curve";
- private static final String TAG_BRIGHTNESS_POINT = "brightness-point";
- private static final String TAG_BRIGHTNESS_CORRECTIONS = "brightness-corrections";
- private static final String TAG_BRIGHTNESS_CORRECTION = "brightness-correction";
- private static final String ATTR_LUX = "lux";
- private static final String ATTR_NITS = "nits";
- private static final String ATTR_DESCRIPTION = "description";
- private static final String ATTR_PACKAGE_NAME = "package-name";
- private static final String ATTR_CATEGORY = "category";
-
private final float[] mLux;
private final float[] mNits;
- private final Map<String, BrightnessCorrection> mCorrectionsByPackageName;
- private final Map<Integer, BrightnessCorrection> mCorrectionsByCategory;
private final String mDescription;
- private BrightnessConfiguration(float[] lux, float[] nits,
- Map<String, BrightnessCorrection> correctionsByPackageName,
- Map<Integer, BrightnessCorrection> correctionsByCategory, String description) {
+ private BrightnessConfiguration(float[] lux, float[] nits, String description) {
mLux = lux;
mNits = nits;
- mCorrectionsByPackageName = correctionsByPackageName;
- mCorrectionsByCategory = correctionsByCategory;
mDescription = description;
}
@@ -84,38 +56,6 @@
}
/**
- * Returns a brightness correction by app, or null.
- *
- * @param packageName
- * The app's package name.
- *
- * @return The matching brightness correction, or null.
- *
- * @hide
- */
- @SystemApi
- @Nullable
- public BrightnessCorrection getCorrectionByPackageName(String packageName) {
- return mCorrectionsByPackageName.get(packageName);
- }
-
- /**
- * Returns a brightness correction by app category, or null.
- *
- * @param category
- * The app category.
- *
- * @return The matching brightness correction, or null.
- *
- * @hide
- */
- @SystemApi
- @Nullable
- public BrightnessCorrection getCorrectionByCategory(int category) {
- return mCorrectionsByCategory.get(category);
- }
-
- /**
* Returns description string.
* @hide
*/
@@ -127,20 +67,6 @@
public void writeToParcel(Parcel dest, int flags) {
dest.writeFloatArray(mLux);
dest.writeFloatArray(mNits);
- dest.writeInt(mCorrectionsByPackageName.size());
- for (Entry<String, BrightnessCorrection> entry : mCorrectionsByPackageName.entrySet()) {
- final String packageName = entry.getKey();
- final BrightnessCorrection correction = entry.getValue();
- dest.writeString(packageName);
- correction.writeToParcel(dest, flags);
- }
- dest.writeInt(mCorrectionsByCategory.size());
- for (Entry<Integer, BrightnessCorrection> entry : mCorrectionsByCategory.entrySet()) {
- final int category = entry.getKey();
- final BrightnessCorrection correction = entry.getValue();
- dest.writeInt(category);
- correction.writeToParcel(dest, flags);
- }
dest.writeString(mDescription);
}
@@ -159,14 +85,7 @@
}
sb.append("(").append(mLux[i]).append(", ").append(mNits[i]).append(")");
}
- sb.append("], {");
- for (Entry<String, BrightnessCorrection> entry : mCorrectionsByPackageName.entrySet()) {
- sb.append("'" + entry.getKey() + "': " + entry.getValue() + ", ");
- }
- for (Entry<Integer, BrightnessCorrection> entry : mCorrectionsByCategory.entrySet()) {
- sb.append(entry.getKey() + ": " + entry.getValue() + ", ");
- }
- sb.append("}, '");
+ sb.append("], '");
if (mDescription != null) {
sb.append(mDescription);
}
@@ -179,8 +98,6 @@
int result = 1;
result = result * 31 + Arrays.hashCode(mLux);
result = result * 31 + Arrays.hashCode(mNits);
- result = result * 31 + mCorrectionsByPackageName.hashCode();
- result = result * 31 + mCorrectionsByCategory.hashCode();
if (mDescription != null) {
result = result * 31 + mDescription.hashCode();
}
@@ -197,8 +114,6 @@
}
final BrightnessConfiguration other = (BrightnessConfiguration) o;
return Arrays.equals(mLux, other.mLux) && Arrays.equals(mNits, other.mNits)
- && mCorrectionsByPackageName.equals(other.mCorrectionsByPackageName)
- && mCorrectionsByCategory.equals(other.mCorrectionsByCategory)
&& Objects.equals(mDescription, other.mDescription);
}
@@ -208,25 +123,7 @@
float[] lux = in.createFloatArray();
float[] nits = in.createFloatArray();
Builder builder = new Builder(lux, nits);
-
- int n = in.readInt();
- for (int i = 0; i < n; i++) {
- final String packageName = in.readString();
- final BrightnessCorrection correction =
- BrightnessCorrection.CREATOR.createFromParcel(in);
- builder.addCorrectionByPackageName(packageName, correction);
- }
-
- n = in.readInt();
- for (int i = 0; i < n; i++) {
- final int category = in.readInt();
- final BrightnessCorrection correction =
- BrightnessCorrection.CREATOR.createFromParcel(in);
- builder.addCorrectionByCategory(category, correction);
- }
-
- final String description = in.readString();
- builder.setDescription(description);
+ builder.setDescription(in.readString());
return builder.build();
}
@@ -236,146 +133,11 @@
};
/**
- * Writes the configuration to an XML serializer.
- *
- * @param serializer
- * The XML serializer.
- *
- * @hide
- */
- public void saveToXml(XmlSerializer serializer) throws IOException {
- serializer.startTag(null, TAG_BRIGHTNESS_CURVE);
- if (mDescription != null) {
- serializer.attribute(null, ATTR_DESCRIPTION, mDescription);
- }
- for (int i = 0; i < mLux.length; i++) {
- serializer.startTag(null, TAG_BRIGHTNESS_POINT);
- serializer.attribute(null, ATTR_LUX, Float.toString(mLux[i]));
- serializer.attribute(null, ATTR_NITS, Float.toString(mNits[i]));
- serializer.endTag(null, TAG_BRIGHTNESS_POINT);
- }
- serializer.endTag(null, TAG_BRIGHTNESS_CURVE);
- serializer.startTag(null, TAG_BRIGHTNESS_CORRECTIONS);
- for (Map.Entry<String, BrightnessCorrection> entry :
- mCorrectionsByPackageName.entrySet()) {
- final String packageName = entry.getKey();
- final BrightnessCorrection correction = entry.getValue();
- serializer.startTag(null, TAG_BRIGHTNESS_CORRECTION);
- serializer.attribute(null, ATTR_PACKAGE_NAME, packageName);
- correction.saveToXml(serializer);
- serializer.endTag(null, TAG_BRIGHTNESS_CORRECTION);
- }
- for (Map.Entry<Integer, BrightnessCorrection> entry : mCorrectionsByCategory.entrySet()) {
- final int category = entry.getKey();
- final BrightnessCorrection correction = entry.getValue();
- serializer.startTag(null, TAG_BRIGHTNESS_CORRECTION);
- serializer.attribute(null, ATTR_CATEGORY, Integer.toString(category));
- correction.saveToXml(serializer);
- serializer.endTag(null, TAG_BRIGHTNESS_CORRECTION);
- }
- serializer.endTag(null, TAG_BRIGHTNESS_CORRECTIONS);
- }
-
- /**
- * Read a configuration from an XML parser.
- *
- * @param parser
- * The XML parser.
- *
- * @throws IOException
- * The parser failed to read the XML file.
- * @throws XmlPullParserException
- * The parser failed to parse the XML file.
- *
- * @hide
- */
- public static BrightnessConfiguration loadFromXml(XmlPullParser parser)
- throws IOException, XmlPullParserException {
- String description = null;
- List<Float> luxList = new ArrayList<>();
- List<Float> nitsList = new ArrayList<>();
- Map<String, BrightnessCorrection> correctionsByPackageName = new HashMap<>();
- Map<Integer, BrightnessCorrection> correctionsByCategory = new HashMap<>();
- final int configDepth = parser.getDepth();
- while (XmlUtils.nextElementWithin(parser, configDepth)) {
- if (TAG_BRIGHTNESS_CURVE.equals(parser.getName())) {
- description = parser.getAttributeValue(null, ATTR_DESCRIPTION);
- final int curveDepth = parser.getDepth();
- while (XmlUtils.nextElementWithin(parser, curveDepth)) {
- if (!TAG_BRIGHTNESS_POINT.equals(parser.getName())) {
- continue;
- }
- final float lux = loadFloatFromXml(parser, ATTR_LUX);
- final float nits = loadFloatFromXml(parser, ATTR_NITS);
- luxList.add(lux);
- nitsList.add(nits);
- }
- }
- if (TAG_BRIGHTNESS_CORRECTIONS.equals(parser.getName())) {
- final int correctionsDepth = parser.getDepth();
- while (XmlUtils.nextElementWithin(parser, correctionsDepth)) {
- if (!TAG_BRIGHTNESS_CORRECTION.equals(parser.getName())) {
- continue;
- }
- final String packageName = parser.getAttributeValue(null, ATTR_PACKAGE_NAME);
- final String categoryText = parser.getAttributeValue(null, ATTR_CATEGORY);
- BrightnessCorrection correction = BrightnessCorrection.loadFromXml(parser);
- if (packageName != null) {
- correctionsByPackageName.put(packageName, correction);
- } else if (categoryText != null) {
- try {
- final int category = Integer.parseInt(categoryText);
- correctionsByCategory.put(category, correction);
- } catch (NullPointerException | NumberFormatException e) {
- continue;
- }
- }
- }
- }
- }
- final int n = luxList.size();
- float[] lux = new float[n];
- float[] nits = new float[n];
- for (int i = 0; i < n; i++) {
- lux[i] = luxList.get(i);
- nits[i] = nitsList.get(i);
- }
- final BrightnessConfiguration.Builder builder = new BrightnessConfiguration.Builder(lux,
- nits);
- builder.setDescription(description);
- for (Map.Entry<String, BrightnessCorrection> entry : correctionsByPackageName.entrySet()) {
- final String packageName = entry.getKey();
- final BrightnessCorrection correction = entry.getValue();
- builder.addCorrectionByPackageName(packageName, correction);
- }
- for (Map.Entry<Integer, BrightnessCorrection> entry : correctionsByCategory.entrySet()) {
- final int category = entry.getKey();
- final BrightnessCorrection correction = entry.getValue();
- builder.addCorrectionByCategory(category, correction);
- }
- return builder.build();
- }
-
- private static float loadFloatFromXml(XmlPullParser parser, String attribute) {
- final String string = parser.getAttributeValue(null, attribute);
- try {
- return Float.parseFloat(string);
- } catch (NullPointerException | NumberFormatException e) {
- return Float.NaN;
- }
- }
-
- /**
* A builder class for {@link BrightnessConfiguration}s.
*/
public static class Builder {
- private static final int MAX_CORRECTIONS_BY_PACKAGE_NAME = 20;
- private static final int MAX_CORRECTIONS_BY_CATEGORY = 20;
-
private float[] mCurveLux;
private float[] mCurveNits;
- private Map<String, BrightnessCorrection> mCorrectionsByPackageName;
- private Map<Integer, BrightnessCorrection> mCorrectionsByCategory;
private String mDescription;
/**
@@ -407,88 +169,6 @@
checkMonotonic(nits, false /*strictly increasing*/, "nits");
mCurveLux = lux;
mCurveNits = nits;
- mCorrectionsByPackageName = new HashMap<>();
- mCorrectionsByCategory = new HashMap<>();
- }
-
- /**
- * Returns the maximum number of corrections by package name allowed.
- *
- * @return The maximum number of corrections by package name allowed.
- *
- * @hide
- */
- @SystemApi
- public int getMaxCorrectionsByPackageName() {
- return MAX_CORRECTIONS_BY_PACKAGE_NAME;
- }
-
- /**
- * Returns the maximum number of corrections by category allowed.
- *
- * @return The maximum number of corrections by category allowed.
- *
- * @hide
- */
- @SystemApi
- public int getMaxCorrectionsByCategory() {
- return MAX_CORRECTIONS_BY_CATEGORY;
- }
-
- /**
- * Add a brightness correction by app package name.
- * This correction is applied whenever an app with this package name has the top activity
- * of the focused stack.
- *
- * @param packageName
- * The app's package name.
- * @param correction
- * The brightness correction.
- *
- * @return The builder.
- *
- * @throws IllegalArgumentExceptions
- * Maximum number of corrections by package name exceeded (see
- * {@link #getMaxCorrectionsByPackageName}).
- *
- * @hide
- */
- @SystemApi
- public Builder addCorrectionByPackageName(String packageName,
- BrightnessCorrection correction) {
- if (mCorrectionsByPackageName.size() >= getMaxCorrectionsByPackageName()) {
- throw new IllegalArgumentException("Too many corrections by package name");
- }
- mCorrectionsByPackageName.put(packageName, correction);
- return this;
- }
-
- /**
- * Add a brightness correction by app category.
- * This correction is applied whenever an app with this category has the top activity of
- * the focused stack, and only if a correction by package name has not been applied.
- *
- * @param category
- * The {@link android.content.pm.ApplicationInfo#category app category}.
- * @param correction
- * The brightness correction.
- *
- * @return The builder.
- *
- * @throws IllegalArgumentException
- * Maximum number of corrections by category exceeded (see
- * {@link #getMaxCorrectionsByCategory}).
- *
- * @hide
- */
- @SystemApi
- public Builder addCorrectionByCategory(@ApplicationInfo.Category int category,
- BrightnessCorrection correction) {
- if (mCorrectionsByCategory.size() >= getMaxCorrectionsByCategory()) {
- throw new IllegalArgumentException("Too many corrections by category");
- }
- mCorrectionsByCategory.put(category, correction);
- return this;
}
/**
@@ -511,8 +191,7 @@
if (mCurveLux == null || mCurveNits == null) {
throw new IllegalStateException("A curve must be set!");
}
- return new BrightnessConfiguration(mCurveLux, mCurveNits, mCorrectionsByPackageName,
- mCorrectionsByCategory, mDescription);
+ return new BrightnessConfiguration(mCurveLux, mCurveNits, mDescription);
}
private static void checkMonotonic(float[] vals, boolean strictlyIncreasing, String name) {
diff --git a/core/java/android/hardware/display/BrightnessCorrection.java b/core/java/android/hardware/display/BrightnessCorrection.java
deleted file mode 100644
index c4e0e3b..0000000
--- a/core/java/android/hardware/display/BrightnessCorrection.java
+++ /dev/null
@@ -1,245 +0,0 @@
-/*
- * Copyright (C) 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.hardware.display;
-
-import android.annotation.NonNull;
-import android.annotation.SystemApi;
-import android.os.Parcel;
-import android.os.Parcelable;
-import android.util.MathUtils;
-
-import com.android.internal.util.XmlUtils;
-
-import org.xmlpull.v1.XmlPullParser;
-import org.xmlpull.v1.XmlPullParserException;
-import org.xmlpull.v1.XmlSerializer;
-
-import java.io.IOException;
-
-/**
- * BrightnessCorrection encapsulates a correction to the brightness, without comitting to the
- * actual correction scheme.
- * It is used by the BrightnessConfiguration, which maps context (e.g. the foreground app's package
- * name and category) to corrections that need to be applied to the brightness within that context.
- * Corrections are currently done by the app that has the top activity of the focused stack, either
- * by its package name, or (if its package name is not mapped to any correction) by its category.
- *
- * @hide
- */
-@SystemApi
-public final class BrightnessCorrection implements Parcelable {
-
- private static final int SCALE_AND_TRANSLATE_LOG = 1;
-
- private static final String TAG_SCALE_AND_TRANSLATE_LOG = "scale-and-translate-log";
-
- private BrightnessCorrectionImplementation mImplementation;
-
- // Parcelable classes must be final, and protected methods are not allowed in APIs, so we can't
- // make this class abstract and use composition instead of inheritence.
- private BrightnessCorrection(BrightnessCorrectionImplementation implementation) {
- mImplementation = implementation;
- }
-
- /**
- * Creates a BrightnessCorrection that given {@code brightness}, corrects it to be
- * {@code exp(scale * log(brightness) + translate)}.
- *
- * @param scale
- * How much to scale the log brightness.
- * @param translate
- * How much to translate the log brightness.
- *
- * @return A BrightnessCorrection that given {@code brightness}, corrects it to be
- * {@code exp(scale * log(brightness) + translate)}.
- *
- * @throws IllegalArgumentException
- * - scale or translate are NaN.
- */
- @NonNull
- public static BrightnessCorrection createScaleAndTranslateLog(float scale, float translate) {
- BrightnessCorrectionImplementation implementation =
- new ScaleAndTranslateLog(scale, translate);
- return new BrightnessCorrection(implementation);
- }
-
- /**
- * Applies the brightness correction to a given brightness.
- *
- * @param brightness
- * The brightness.
- *
- * @return The corrected brightness.
- */
- public float apply(float brightness) {
- return mImplementation.apply(brightness);
- }
-
- /**
- * Returns a string representation.
- *
- * @return A string representation.
- */
- public String toString() {
- return mImplementation.toString();
- }
-
- public static final Creator<BrightnessCorrection> CREATOR =
- new Creator<BrightnessCorrection>() {
- public BrightnessCorrection createFromParcel(Parcel in) {
- final int type = in.readInt();
- switch (type) {
- case SCALE_AND_TRANSLATE_LOG:
- return ScaleAndTranslateLog.readFromParcel(in);
- }
- return null;
- }
-
- public BrightnessCorrection[] newArray(int size) {
- return new BrightnessCorrection[size];
- }
- };
-
- @Override
- public void writeToParcel(Parcel dest, int flags) {
- mImplementation.writeToParcel(dest);
- }
-
- @Override
- public int describeContents() {
- return 0;
- }
-
- /**
- * Writes the correction to an XML serializer.
- *
- * @param serializer
- * The XML serializer.
- *
- * @hide
- */
- public void saveToXml(XmlSerializer serializer) throws IOException {
- mImplementation.saveToXml(serializer);
- }
-
- /**
- * Read a correction from an XML parser.
- *
- * @param parser
- * The XML parser.
- *
- * @throws IOException
- * The parser failed to read the XML file.
- * @throws XmlPullParserException
- * The parser failed to parse the XML file.
- *
- * @hide
- */
- public static BrightnessCorrection loadFromXml(XmlPullParser parser) throws IOException,
- XmlPullParserException {
- final int depth = parser.getDepth();
- while (XmlUtils.nextElementWithin(parser, depth)) {
- if (TAG_SCALE_AND_TRANSLATE_LOG.equals(parser.getName())) {
- return ScaleAndTranslateLog.loadFromXml(parser);
- }
- }
- return null;
- }
-
- private static float loadFloatFromXml(XmlPullParser parser, String attribute) {
- final String string = parser.getAttributeValue(null, attribute);
- try {
- return Float.parseFloat(string);
- } catch (NullPointerException | NumberFormatException e) {
- return Float.NaN;
- }
- }
-
- private interface BrightnessCorrectionImplementation {
- float apply(float brightness);
- String toString();
- void writeToParcel(Parcel dest);
- void saveToXml(XmlSerializer serializer) throws IOException;
- // Package-private static methods:
- // static BrightnessCorrection readFromParcel(Parcel in);
- // static BrightnessCorrection loadFromXml(XmlPullParser parser) throws IOException,
- // XmlPullParserException;
- }
-
- /**
- * A BrightnessCorrection that given {@code brightness}, corrects it to be
- * {@code exp(scale * log(brightness) + translate)}.
- */
- private static class ScaleAndTranslateLog implements BrightnessCorrectionImplementation {
- private static final float MIN_SCALE = 0.5f;
- private static final float MAX_SCALE = 2.0f;
- private static final float MIN_TRANSLATE = -0.6f;
- private static final float MAX_TRANSLATE = 0.7f;
-
- private static final String ATTR_SCALE = "scale";
- private static final String ATTR_TRANSLATE = "translate";
-
- private final float mScale;
- private final float mTranslate;
-
- ScaleAndTranslateLog(float scale, float translate) {
- if (Float.isNaN(scale) || Float.isNaN(translate)) {
- throw new IllegalArgumentException("scale and translate must be numbers");
- }
- mScale = MathUtils.constrain(scale, MIN_SCALE, MAX_SCALE);
- mTranslate = MathUtils.constrain(translate, MIN_TRANSLATE, MAX_TRANSLATE);
- }
-
- @Override
- public float apply(float brightness) {
- return MathUtils.exp(mScale * MathUtils.log(brightness) + mTranslate);
- }
-
- @Override
- public String toString() {
- return "ScaleAndTranslateLog(" + mScale + ", " + mTranslate + ")";
- }
-
- @Override
- public void writeToParcel(Parcel dest) {
- dest.writeInt(SCALE_AND_TRANSLATE_LOG);
- dest.writeFloat(mScale);
- dest.writeFloat(mTranslate);
- }
-
- @Override
- public void saveToXml(XmlSerializer serializer) throws IOException {
- serializer.startTag(null, TAG_SCALE_AND_TRANSLATE_LOG);
- serializer.attribute(null, ATTR_SCALE, Float.toString(mScale));
- serializer.attribute(null, ATTR_TRANSLATE, Float.toString(mTranslate));
- serializer.endTag(null, TAG_SCALE_AND_TRANSLATE_LOG);
- }
-
- static BrightnessCorrection readFromParcel(Parcel in) {
- float scale = in.readFloat();
- float translate = in.readFloat();
- return BrightnessCorrection.createScaleAndTranslateLog(scale, translate);
- }
-
- static BrightnessCorrection loadFromXml(XmlPullParser parser) throws IOException,
- XmlPullParserException {
- final float scale = loadFloatFromXml(parser, ATTR_SCALE);
- final float translate = loadFloatFromXml(parser, ATTR_TRANSLATE);
- return BrightnessCorrection.createScaleAndTranslateLog(scale, translate);
- }
- }
-}
diff --git a/core/java/android/net/NetworkStats.java b/core/java/android/net/NetworkStats.java
index a00b9a3..9cf582b 100644
--- a/core/java/android/net/NetworkStats.java
+++ b/core/java/android/net/NetworkStats.java
@@ -16,6 +16,8 @@
package android.net;
+import static android.os.Process.CLAT_UID;
+
import android.annotation.UnsupportedAppUsage;
import android.os.Parcel;
import android.os.Parcelable;
@@ -828,13 +830,15 @@
*
* <p>For 464xlat traffic, xt_qtaguid sees every IPv4 packet twice, once as a native IPv4
* packet on the stacked interface, and once as translated to an IPv6 packet on the
- * base interface. For correct stats accounting on the base interface, every 464xlat
- * packet needs to be subtracted from the root UID on the base interface both for tx
- * and rx traffic (http://b/12249687, http:/b/33681750).
+ * base interface. For correct stats accounting on the base interface, if using xt_qtaguid,
+ * every rx 464xlat packet needs to be subtracted from the root UID on the base interface
+ * (http://b/12249687, http:/b/33681750), and every tx 464xlat packet which was counted onto
+ * clat uid should be ignored.
*
* As for eBPF, the per uid stats is collected by different hook, the rx packets on base
- * interface will not be counted. Thus, the adjustment on root uid is only needed in tx
- * direction.
+ * interface will not be counted. Thus, the adjustment on root uid is not needed. However, the
+ * tx traffic counted in the same way xt_qtaguid does, so the traffic on clat uid still
+ * needs to be ignored.
*
* <p>This method will behave fine if {@code stackedIfaces} is an non-synchronized but add-only
* {@code ConcurrentHashMap}
@@ -862,17 +866,14 @@
if (baseIface == null) {
continue;
}
- // Subtract any 464lat traffic seen for the root UID on the current base interface.
- // However, for eBPF, the per uid stats is collected by different hook, the rx packets
- // on base interface will not be counted. Thus, the adjustment on root uid is only
- // needed in tx direction.
+ // Subtract xt_qtaguid 464lat rx traffic seen for the root UID on the current base
+ // interface. As for eBPF, the per uid stats is collected by different hook, the rx
+ // packets on base interface will not be counted.
adjust.iface = baseIface;
if (!useBpfStats) {
adjust.rxBytes = -(entry.rxBytes + entry.rxPackets * IPV4V6_HEADER_DELTA);
adjust.rxPackets = -entry.rxPackets;
}
- adjust.txBytes = -(entry.txBytes + entry.txPackets * IPV4V6_HEADER_DELTA);
- adjust.txPackets = -entry.txPackets;
adjustments.combineValues(adjust);
// For 464xlat traffic, per uid stats only counts the bytes of the native IPv4 packet
@@ -884,6 +885,9 @@
stackedTraffic.setValues(i, entry);
}
+ // Traffic on clat uid is v6 tx traffic that is already counted with app uid on the stacked
+ // v4 interface, so it needs to be removed to avoid double-counting.
+ baseTraffic.removeUids(new int[] {CLAT_UID});
baseTraffic.combineAllValues(adjustments);
}
diff --git a/core/java/android/nfc/INfcCardEmulation.aidl b/core/java/android/nfc/INfcCardEmulation.aidl
index d1b132c..dd2c0d4 100644
--- a/core/java/android/nfc/INfcCardEmulation.aidl
+++ b/core/java/android/nfc/INfcCardEmulation.aidl
@@ -31,6 +31,8 @@
boolean setDefaultServiceForCategory(int userHandle, in ComponentName service, String category);
boolean setDefaultForNextTap(int userHandle, in ComponentName service);
boolean registerAidGroupForService(int userHandle, in ComponentName service, in AidGroup aidGroup);
+ boolean setOffHostForService(int userHandle, in ComponentName service, in String offHostSecureElement);
+ boolean unsetOffHostForService(int userHandle, in ComponentName service);
AidGroup getAidGroupForService(int userHandle, in ComponentName service, String category);
boolean removeAidGroupForService(int userHandle, in ComponentName service, String category);
List<ApduServiceInfo> getServices(int userHandle, in String category);
diff --git a/core/java/android/nfc/NfcAdapter.java b/core/java/android/nfc/NfcAdapter.java
index 21fed48..e55e036 100644
--- a/core/java/android/nfc/NfcAdapter.java
+++ b/core/java/android/nfc/NfcAdapter.java
@@ -16,6 +16,7 @@
package android.nfc;
+import android.annotation.NonNull;
import android.annotation.RequiresPermission;
import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
@@ -42,7 +43,9 @@
import android.util.Log;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
/**
* Represents the local NFC adapter.
@@ -322,6 +325,7 @@
// Guarded by NfcAdapter.class
static boolean sIsInitialized = false;
static boolean sHasNfcFeature;
+ static boolean sHasBeamFeature;
// Final after first constructor, except for
// attemptDeadServiceRecovery() when NFC crashes - we accept a best effort
@@ -369,7 +373,9 @@
* A callback to be invoked when the system successfully delivers your {@link NdefMessage}
* to another device.
* @see #setOnNdefPushCompleteCallback
+ * @deprecated this feature is deprecated.
*/
+ @java.lang.Deprecated
public interface OnNdefPushCompleteCallback {
/**
* Called on successful NDEF push.
@@ -392,7 +398,9 @@
* content currently visible to the user. Alternatively, you can call {@link
* #setNdefPushMessage setNdefPushMessage()} if the {@link NdefMessage} always contains the
* same data.
+ * @deprecated this feature is deprecated.
*/
+ @java.lang.Deprecated
public interface CreateNdefMessageCallback {
/**
* Called to provide a {@link NdefMessage} to push.
@@ -418,7 +426,10 @@
}
- // TODO javadoc
+ /**
+ * @deprecated this feature is deprecated.
+ */
+ @java.lang.Deprecated
public interface CreateBeamUrisCallback {
public Uri[] createBeamUris(NfcEvent event);
}
@@ -446,6 +457,25 @@
public boolean onUnlockAttempted(Tag tag);
}
+ /**
+ * Helper to check if this device has FEATURE_NFC_BEAM, but without using
+ * a context.
+ * Equivalent to
+ * context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC_BEAM)
+ */
+ private static boolean hasBeamFeature() {
+ IPackageManager pm = ActivityThread.getPackageManager();
+ if (pm == null) {
+ Log.e(TAG, "Cannot get package manager, assuming no Android Beam feature");
+ return false;
+ }
+ try {
+ return pm.hasSystemFeature(PackageManager.FEATURE_NFC_BEAM, 0);
+ } catch (RemoteException e) {
+ Log.e(TAG, "Package manager query failed, assuming no Android Beam feature", e);
+ return false;
+ }
+ }
/**
* Helper to check if this device has FEATURE_NFC, but without using
@@ -488,6 +518,35 @@
}
/**
+ * Return list of Secure Elements which support off host card emulation.
+ *
+ * @return List<String> containing secure elements on the device which supports
+ * off host card emulation. eSE for Embedded secure element,
+ * SIM for UICC and so on.
+ */
+ public @NonNull List<String> getSupportedOffHostSecureElements() {
+ List<String> offHostSE = new ArrayList<String>();
+ IPackageManager pm = ActivityThread.getPackageManager();
+ if (pm == null) {
+ Log.e(TAG, "Cannot get package manager, assuming no off-host CE feature");
+ return offHostSE;
+ }
+ try {
+ if (pm.hasSystemFeature(PackageManager.FEATURE_NFC_OFF_HOST_CARD_EMULATION_UICC, 0)) {
+ offHostSE.add("SIM");
+ }
+ if (pm.hasSystemFeature(PackageManager.FEATURE_NFC_OFF_HOST_CARD_EMULATION_ESE, 0)) {
+ offHostSE.add("eSE");
+ }
+ } catch (RemoteException e) {
+ Log.e(TAG, "Package manager query failed, assuming no off-host CE feature", e);
+ offHostSE.clear();
+ return offHostSE;
+ }
+ return offHostSE;
+ }
+
+ /**
* Returns the NfcAdapter for application context,
* or throws if NFC is not available.
* @hide
@@ -496,6 +555,7 @@
public static synchronized NfcAdapter getNfcAdapter(Context context) {
if (!sIsInitialized) {
sHasNfcFeature = hasNfcFeature();
+ sHasBeamFeature = hasBeamFeature();
boolean hasHceFeature = hasNfcHceFeature();
/* is this device meant to have NFC */
if (!sHasNfcFeature && !hasHceFeature) {
@@ -921,12 +981,17 @@
* @param uris an array of Uri(s) to push over Android Beam
* @param activity activity for which the Uri(s) will be pushed
* @throws UnsupportedOperationException if FEATURE_NFC is unavailable.
+ * @deprecated this feature is deprecated.
*/
+ @java.lang.Deprecated
public void setBeamPushUris(Uri[] uris, Activity activity) {
synchronized (NfcAdapter.class) {
if (!sHasNfcFeature) {
throw new UnsupportedOperationException();
}
+ if (!sHasBeamFeature) {
+ return;
+ }
}
if (activity == null) {
throw new NullPointerException("activity cannot be null");
@@ -1003,12 +1068,17 @@
* @param callback callback, or null to disable
* @param activity activity for which the Uri(s) will be pushed
* @throws UnsupportedOperationException if FEATURE_NFC is unavailable.
+ * @deprecated this feature is deprecated.
*/
+ @java.lang.Deprecated
public void setBeamPushUrisCallback(CreateBeamUrisCallback callback, Activity activity) {
synchronized (NfcAdapter.class) {
if (!sHasNfcFeature) {
throw new UnsupportedOperationException();
}
+ if (!sHasBeamFeature) {
+ return;
+ }
}
if (activity == null) {
throw new NullPointerException("activity cannot be null");
@@ -1087,13 +1157,18 @@
* to only register one at a time, and to do so in that activity's
* {@link Activity#onCreate}
* @throws UnsupportedOperationException if FEATURE_NFC is unavailable.
+ * @deprecated this feature is deprecated.
*/
+ @java.lang.Deprecated
public void setNdefPushMessage(NdefMessage message, Activity activity,
Activity ... activities) {
synchronized (NfcAdapter.class) {
if (!sHasNfcFeature) {
throw new UnsupportedOperationException();
}
+ if (!sHasBeamFeature) {
+ return;
+ }
}
int targetSdkVersion = getSdkVersion();
try {
@@ -1200,13 +1275,18 @@
* to only register one at a time, and to do so in that activity's
* {@link Activity#onCreate}
* @throws UnsupportedOperationException if FEATURE_NFC is unavailable.
+ * @deprecated this feature is deprecated.
*/
+ @java.lang.Deprecated
public void setNdefPushMessageCallback(CreateNdefMessageCallback callback, Activity activity,
Activity ... activities) {
synchronized (NfcAdapter.class) {
if (!sHasNfcFeature) {
throw new UnsupportedOperationException();
}
+ if (!sHasBeamFeature) {
+ return;
+ }
}
int targetSdkVersion = getSdkVersion();
try {
@@ -1281,13 +1361,18 @@
* to only register one at a time, and to do so in that activity's
* {@link Activity#onCreate}
* @throws UnsupportedOperationException if FEATURE_NFC is unavailable.
+ * @deprecated this feature is deprecated.
*/
+ @java.lang.Deprecated
public void setOnNdefPushCompleteCallback(OnNdefPushCompleteCallback callback,
Activity activity, Activity ... activities) {
synchronized (NfcAdapter.class) {
if (!sHasNfcFeature) {
throw new UnsupportedOperationException();
}
+ if (!sHasBeamFeature) {
+ return;
+ }
}
int targetSdkVersion = getSdkVersion();
try {
@@ -1492,12 +1577,17 @@
* @param activity the current foreground Activity that has registered data to share
* @return whether the Beam animation was successfully invoked
* @throws UnsupportedOperationException if FEATURE_NFC is unavailable.
+ * @deprecated this feature is deprecated.
*/
+ @java.lang.Deprecated
public boolean invokeBeam(Activity activity) {
synchronized (NfcAdapter.class) {
if (!sHasNfcFeature) {
throw new UnsupportedOperationException();
}
+ if (!sHasBeamFeature) {
+ return false;
+ }
}
if (activity == null) {
throw new NullPointerException("activity may not be null.");
@@ -1561,6 +1651,9 @@
if (!sHasNfcFeature) {
throw new UnsupportedOperationException();
}
+ if (!sHasBeamFeature) {
+ return;
+ }
}
if (activity == null || message == null) {
throw new NullPointerException();
@@ -1595,6 +1688,9 @@
if (!sHasNfcFeature) {
throw new UnsupportedOperationException();
}
+ if (!sHasBeamFeature) {
+ return;
+ }
}
if (activity == null) {
throw new NullPointerException();
@@ -1668,12 +1764,18 @@
* @see android.provider.Settings#ACTION_NFCSHARING_SETTINGS
* @return true if NDEF Push feature is enabled
* @throws UnsupportedOperationException if FEATURE_NFC is unavailable.
+ * @deprecated this feature is deprecated.
*/
+ @java.lang.Deprecated
+
public boolean isNdefPushEnabled() {
synchronized (NfcAdapter.class) {
if (!sHasNfcFeature) {
throw new UnsupportedOperationException();
}
+ if (!sHasBeamFeature) {
+ return false;
+ }
}
try {
return sService.isNdefPushEnabled();
diff --git a/core/java/android/nfc/cardemulation/ApduServiceInfo.java b/core/java/android/nfc/cardemulation/ApduServiceInfo.java
index e8d801c..911ec84 100644
--- a/core/java/android/nfc/cardemulation/ApduServiceInfo.java
+++ b/core/java/android/nfc/cardemulation/ApduServiceInfo.java
@@ -18,11 +18,10 @@
import android.annotation.UnsupportedAppUsage;
import android.content.ComponentName;
-import android.content.Context;
import android.content.pm.PackageManager;
+import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
-import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;
import android.content.res.Resources.NotFoundException;
import android.content.res.TypedArray;
@@ -30,7 +29,6 @@
import android.graphics.drawable.Drawable;
import android.os.Parcel;
import android.os.Parcelable;
-import android.os.ResultReceiver;
import android.util.AttributeSet;
import android.util.Log;
import android.util.Xml;
@@ -69,6 +67,18 @@
final boolean mOnHost;
/**
+ * Offhost reader name.
+ * eg: SIM, eSE etc
+ */
+ String mOffHostName;
+
+ /**
+ * Offhost reader name from manifest file.
+ * Used for unsetOffHostSecureElement()
+ */
+ final String mStaticOffHostName;
+
+ /**
* Mapping from category to static AID group
*/
@UnsupportedAppUsage
@@ -104,15 +114,17 @@
* @hide
*/
@UnsupportedAppUsage
- public ApduServiceInfo(ResolveInfo info, boolean onHost, String description,
+ public ApduServiceInfo(ResolveInfo info, String description,
ArrayList<AidGroup> staticAidGroups, ArrayList<AidGroup> dynamicAidGroups,
boolean requiresUnlock, int bannerResource, int uid,
- String settingsActivityName) {
+ String settingsActivityName, String offHost, String staticOffHost) {
this.mService = info;
this.mDescription = description;
this.mStaticAidGroups = new HashMap<String, AidGroup>();
this.mDynamicAidGroups = new HashMap<String, AidGroup>();
- this.mOnHost = onHost;
+ this.mOffHostName = offHost;
+ this.mStaticOffHostName = staticOffHost;
+ this.mOnHost = (offHost == null);
this.mRequiresDeviceUnlock = requiresUnlock;
for (AidGroup aidGroup : staticAidGroups) {
this.mStaticAidGroups.put(aidGroup.category, aidGroup);
@@ -174,6 +186,8 @@
com.android.internal.R.styleable.HostApduService_apduServiceBanner, -1);
mSettingsActivityName = sa.getString(
com.android.internal.R.styleable.HostApduService_settingsActivity);
+ mOffHostName = null;
+ mStaticOffHostName = mOffHostName;
sa.recycle();
} else {
TypedArray sa = res.obtainAttributes(attrs,
@@ -186,6 +200,16 @@
com.android.internal.R.styleable.OffHostApduService_apduServiceBanner, -1);
mSettingsActivityName = sa.getString(
com.android.internal.R.styleable.HostApduService_settingsActivity);
+ mOffHostName = sa.getString(
+ com.android.internal.R.styleable.OffHostApduService_secureElementName);
+ if (mOffHostName != null) {
+ if (mOffHostName.equals("eSE")) {
+ mOffHostName = "eSE1";
+ } else if (mOffHostName.equals("SIM")) {
+ mOffHostName = "SIM1";
+ }
+ }
+ mStaticOffHostName = mOffHostName;
sa.recycle();
}
@@ -289,6 +313,10 @@
mService.serviceInfo.name);
}
+ public String getOffHostSecureElement() {
+ return mOffHostName;
+ }
+
/**
* Returns a consolidated list of AIDs from the AID groups
* registered by this service. Note that if a service has both
@@ -404,6 +432,20 @@
mDynamicAidGroups.put(aidGroup.getCategory(), aidGroup);
}
+ @UnsupportedAppUsage
+ public void setOffHostSecureElement(String offHost) {
+ mOffHostName = offHost;
+ }
+
+ /**
+ * Resets the off host Secure Element to statically defined
+ * by the service in the manifest file.
+ */
+ @UnsupportedAppUsage
+ public void unsetOffHostSecureElement() {
+ mOffHostName = mStaticOffHostName;
+ }
+
public CharSequence loadLabel(PackageManager pm) {
return mService.loadLabel(pm);
}
@@ -481,6 +523,8 @@
mService.writeToParcel(dest, flags);
dest.writeString(mDescription);
dest.writeInt(mOnHost ? 1 : 0);
+ dest.writeString(mOffHostName);
+ dest.writeString(mStaticOffHostName);
dest.writeInt(mStaticAidGroups.size());
if (mStaticAidGroups.size() > 0) {
dest.writeTypedList(new ArrayList<AidGroup>(mStaticAidGroups.values()));
@@ -503,6 +547,8 @@
ResolveInfo info = ResolveInfo.CREATOR.createFromParcel(source);
String description = source.readString();
boolean onHost = source.readInt() != 0;
+ String offHostName = source.readString();
+ String staticOffHostName = source.readString();
ArrayList<AidGroup> staticAidGroups = new ArrayList<AidGroup>();
int numStaticGroups = source.readInt();
if (numStaticGroups > 0) {
@@ -517,9 +563,9 @@
int bannerResource = source.readInt();
int uid = source.readInt();
String settingsActivityName = source.readString();
- return new ApduServiceInfo(info, onHost, description, staticAidGroups,
+ return new ApduServiceInfo(info, description, staticAidGroups,
dynamicAidGroups, requiresUnlock, bannerResource, uid,
- settingsActivityName);
+ settingsActivityName, offHostName, staticOffHostName);
}
@Override
@@ -531,6 +577,14 @@
public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
pw.println(" " + getComponent() +
" (Description: " + getDescription() + ")");
+ if (mOnHost) {
+ pw.println(" On Host Service");
+ } else {
+ pw.println(" Off-host Service");
+ pw.println(" " + "Current off-host SE" + mOffHostName
+ + " static off-host: " + mOffHostName);
+ }
+ pw.println(" Static off-host Secure Element:");
pw.println(" Static AID groups:");
for (AidGroup group : mStaticAidGroups.values()) {
pw.println(" Category: " + group.category);
diff --git a/core/java/android/nfc/cardemulation/CardEmulation.java b/core/java/android/nfc/cardemulation/CardEmulation.java
index 15d02f2..01932ab 100644
--- a/core/java/android/nfc/cardemulation/CardEmulation.java
+++ b/core/java/android/nfc/cardemulation/CardEmulation.java
@@ -27,7 +27,6 @@
import android.nfc.INfcCardEmulation;
import android.nfc.NfcAdapter;
import android.os.RemoteException;
-import android.os.UserHandle;
import android.provider.Settings;
import android.provider.Settings.SettingNotFoundException;
import android.util.Log;
@@ -345,6 +344,108 @@
}
/**
+ * Unsets the off-host Secure Element for the given service.
+ *
+ * <p>Note that this will only remove Secure Element that was dynamically
+ * set using the {@link #setOffHostForService(ComponentName, String)}
+ * and resets it to a value that was statically assigned using manifest.
+ *
+ * <p>Note that you can only unset off-host SE for a service that
+ * is running under the same UID as the caller of this API. Typically
+ * this means you need to call this from the same
+ * package as the service itself, though UIDs can also
+ * be shared between packages using shared UIDs.
+ *
+ * @param service The component name of the service
+ * @return whether the registration was successful.
+ */
+ public boolean unsetOffHostForService(ComponentName service) {
+ NfcAdapter adapter = NfcAdapter.getDefaultAdapter(mContext);
+ if (adapter == null) {
+ return false;
+ }
+
+ try {
+ return sService.unsetOffHostForService(mContext.getUserId(), service);
+ } catch (RemoteException e) {
+ // Try one more time
+ recoverService();
+ if (sService == null) {
+ Log.e(TAG, "Failed to recover CardEmulationService.");
+ return false;
+ }
+ try {
+ return sService.unsetOffHostForService(mContext.getUserId(), service);
+ } catch (RemoteException ee) {
+ Log.e(TAG, "Failed to reach CardEmulationService.");
+ return false;
+ }
+ }
+ }
+
+ /**
+ * Sets the off-host Secure Element for the given service.
+ *
+ * <p>If off-host SE was initially set (either statically
+ * through the manifest, or dynamically by using this API),
+ * it will be replaced with this one. All AIDs registered by
+ * this service will be re-routed to this Secure Element if
+ * successful.
+ *
+ * <p>Note that you can only set off-host SE for a service that
+ * is running under the same UID as the caller of this API. Typically
+ * this means you need to call this from the same
+ * package as the service itself, though UIDs can also
+ * be shared between packages using shared UIDs.
+ *
+ * <p>Registeration will be successful only if the Secure Element
+ * exists on the device.
+ *
+ * @param service The component name of the service
+ * @param offHostSecureElement Secure Element to register the AID to
+ * @return whether the registration was successful.
+ */
+ public boolean setOffHostForService(ComponentName service, String offHostSecureElement) {
+ boolean validSecureElement = false;
+
+ NfcAdapter adapter = NfcAdapter.getDefaultAdapter(mContext);
+ if (adapter == null || offHostSecureElement == null) {
+ return false;
+ }
+
+ List<String> validSE = adapter.getSupportedOffHostSecureElements();
+ if ((offHostSecureElement.startsWith("eSE") && !validSE.contains("eSE"))
+ || (offHostSecureElement.startsWith("SIM") && !validSE.contains("SIM"))) {
+ return false;
+ }
+
+ if (offHostSecureElement.equals("eSE")) {
+ offHostSecureElement = "eSE1";
+ } else if (offHostSecureElement.equals("SIM")) {
+ offHostSecureElement = "SIM1";
+ }
+
+ try {
+ return sService.setOffHostForService(mContext.getUserId(), service,
+ offHostSecureElement);
+ } catch (RemoteException e) {
+ // Try one more time
+ recoverService();
+ if (sService == null) {
+ Log.e(TAG, "Failed to recover CardEmulationService.");
+ return false;
+ }
+ try {
+ return sService.setOffHostForService(mContext.getUserId(), service,
+ offHostSecureElement);
+ } catch (RemoteException ee) {
+ Log.e(TAG, "Failed to reach CardEmulationService.");
+ return false;
+ }
+ }
+ }
+
+ /**
* Retrieves the currently registered AIDs for the specified
* category for a service.
*
diff --git a/core/java/android/os/Process.java b/core/java/android/os/Process.java
index 505aec2..938b23c 100644
--- a/core/java/android/os/Process.java
+++ b/core/java/android/os/Process.java
@@ -111,6 +111,12 @@
public static final int NFC_UID = 1027;
/**
+ * Defines the UID/GID for the clatd process.
+ * @hide
+ * */
+ public static final int CLAT_UID = 1029;
+
+ /**
* Defines the UID/GID for the Bluetooth service process.
* @hide
*/
diff --git a/core/java/android/permission/IRuntimePermissionPresenter.aidl b/core/java/android/permission/IPermissionController.aidl
similarity index 89%
rename from core/java/android/permission/IRuntimePermissionPresenter.aidl
rename to core/java/android/permission/IPermissionController.aidl
index e95428a..38951d5 100644
--- a/core/java/android/permission/IRuntimePermissionPresenter.aidl
+++ b/core/java/android/permission/IPermissionController.aidl
@@ -19,11 +19,11 @@
import android.os.RemoteCallback;
/**
- * Interface for communication with the permission presenter service.
+ * Interface for system apps to communication with the permission controller.
*
* @hide
*/
-oneway interface IRuntimePermissionPresenter {
+oneway interface IPermissionController {
void getAppPermissions(String packageName, in RemoteCallback callback);
void revokeRuntimePermission(String packageName, String permissionName);
void countPermissionApps(in List<String> permissionNames, boolean countOnlyGranted,
diff --git a/core/java/android/permission/RuntimePermissionPresenter.java b/core/java/android/permission/PermissionControllerManager.java
similarity index 82%
rename from core/java/android/permission/RuntimePermissionPresenter.java
rename to core/java/android/permission/PermissionControllerManager.java
index c607e3f..66e8666 100644
--- a/core/java/android/permission/RuntimePermissionPresenter.java
+++ b/core/java/android/permission/PermissionControllerManager.java
@@ -16,13 +16,16 @@
package android.permission;
-import static android.permission.RuntimePermissionPresenterService.SERVICE_INTERFACE;
+import static android.permission.PermissionControllerService.SERVICE_INTERFACE;
import static com.android.internal.util.Preconditions.checkCollectionElementsNotNull;
import static com.android.internal.util.Preconditions.checkNotNull;
+import android.Manifest;
import android.annotation.NonNull;
import android.annotation.Nullable;
+import android.annotation.RequiresPermission;
+import android.annotation.SystemService;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
@@ -34,7 +37,6 @@
import android.os.UserHandle;
import android.util.Log;
-import com.android.internal.annotations.GuardedBy;
import com.android.internal.infra.AbstractMultiplePendingRequestsRemoteService;
import com.android.internal.infra.AbstractRemoteService;
@@ -42,29 +44,24 @@
import java.util.List;
/**
- * This class provides information about runtime permissions for a specific
- * app or all apps. This information is dedicated for presentation purposes
- * and does not necessarily reflect the individual permissions requested/
- * granted to an app as the platform may be grouping permissions to improve
- * presentation and help the user make an informed choice. For example, all
- * runtime permissions in the same permission group may be presented as a
- * single permission in the UI.
+ * Interface for communicating with the permission controller from system apps. All UI operations
+ * regarding permissions and any changes to the permission state should flow through this
+ * interface.
*
* @hide
*/
-public final class RuntimePermissionPresenter {
- private static final String TAG = "RuntimePermPresenter";
+@SystemService(Context.PERMISSION_CONTROLLER_SERVICE)
+public final class PermissionControllerManager {
+ private static final String TAG = PermissionControllerManager.class.getSimpleName();
/**
* The key for retrieving the result from the returned bundle.
- *
- * @hide
*/
public static final String KEY_RESULT =
- "android.permission.RuntimePermissionPresenter.key.result";
+ "android.permission.PermissionControllerManager.key.result";
/**
- * Listener for delivering the result of {@link #getAppPermissions}.
+ * Callback for delivering the result of {@link #getAppPermissions}.
*/
public interface OnGetAppPermissionResultCallback {
/**
@@ -77,7 +74,7 @@
}
/**
- * Listener for delivering the result of {@link #countPermissionApps}.
+ * Callback for delivering the result of {@link #countPermissionApps}.
*/
public interface OnCountPermissionAppsResultCallback {
/**
@@ -89,29 +86,9 @@
void onCountPermissionApps(int numApps);
}
- private static final Object sLock = new Object();
-
- @GuardedBy("sLock")
- private static RuntimePermissionPresenter sInstance;
-
private final RemoteService mRemoteService;
- /**
- * Gets the singleton runtime permission presenter.
- *
- * @param context Context for accessing resources.
- * @return The singleton instance.
- */
- public static RuntimePermissionPresenter getInstance(@NonNull Context context) {
- synchronized (sLock) {
- if (sInstance == null) {
- sInstance = new RuntimePermissionPresenter(context.getApplicationContext());
- }
- return sInstance;
- }
- }
-
- private RuntimePermissionPresenter(@NonNull Context context) {
+ public PermissionControllerManager(@NonNull Context context) {
Intent intent = new Intent(SERVICE_INTERFACE);
intent.setPackage(context.getPackageManager().getPermissionControllerPackageName());
ResolveInfo serviceInfo = context.getPackageManager().resolveService(intent, 0);
@@ -127,6 +104,7 @@
* @param callback Callback to receive the result.
* @param handler Handler on which to invoke the callback.
*/
+ @RequiresPermission(Manifest.permission.GET_RUNTIME_PERMISSIONS)
public void getAppPermissions(@NonNull String packageName,
@NonNull OnGetAppPermissionResultCallback callback, @Nullable Handler handler) {
checkNotNull(packageName);
@@ -142,6 +120,7 @@
* @param packageName The package for which to revoke
* @param permissionName The permission to revoke
*/
+ @RequiresPermission(Manifest.permission.REVOKE_RUNTIME_PERMISSIONS)
public void revokeRuntimePermission(@NonNull String packageName,
@NonNull String permissionName) {
checkNotNull(packageName);
@@ -160,6 +139,7 @@
* @param callback Callback to receive the result
* @param handler Handler on which to invoke the callback
*/
+ @RequiresPermission(Manifest.permission.GET_RUNTIME_PERMISSIONS)
public void countPermissionApps(@NonNull List<String> permissionNames,
boolean countOnlyGranted, boolean countSystem,
@NonNull OnCountPermissionAppsResultCallback callback, @Nullable Handler handler) {
@@ -175,8 +155,7 @@
* A connection to the remote service
*/
static final class RemoteService extends
- AbstractMultiplePendingRequestsRemoteService<RemoteService,
- IRuntimePermissionPresenter> {
+ AbstractMultiplePendingRequestsRemoteService<RemoteService, IPermissionController> {
private static final long UNBIND_TIMEOUT_MILLIS = 10000;
private static final long MESSAGE_TIMEOUT_MILLIS = 30000;
@@ -200,9 +179,8 @@
}
@Override
- protected @NonNull IRuntimePermissionPresenter getServiceInterface(
- @NonNull IBinder binder) {
- return IRuntimePermissionPresenter.Stub.asInterface(binder);
+ protected @NonNull IPermissionController getServiceInterface(@NonNull IBinder binder) {
+ return IPermissionController.Stub.asInterface(binder);
}
@Override
@@ -217,13 +195,12 @@
@Override
public void scheduleRequest(@NonNull PendingRequest<RemoteService,
- IRuntimePermissionPresenter> pendingRequest) {
+ IPermissionController> pendingRequest) {
super.scheduleRequest(pendingRequest);
}
@Override
- public void scheduleAsyncRequest(
- @NonNull AsyncRequest<IRuntimePermissionPresenter> request) {
+ public void scheduleAsyncRequest(@NonNull AsyncRequest<IPermissionController> request) {
super.scheduleAsyncRequest(request);
}
}
@@ -232,7 +209,7 @@
* Request for {@link #getAppPermissions}
*/
private static final class PendingGetAppPermissionRequest extends
- AbstractRemoteService.PendingRequest<RemoteService, IRuntimePermissionPresenter> {
+ AbstractRemoteService.PendingRequest<RemoteService, IPermissionController> {
private final @NonNull String mPackageName;
private final @NonNull OnGetAppPermissionResultCallback mCallback;
@@ -282,7 +259,7 @@
* Request for {@link #revokeRuntimePermission}
*/
private static final class PendingRevokeAppPermissionRequest
- implements AbstractRemoteService.AsyncRequest<IRuntimePermissionPresenter> {
+ implements AbstractRemoteService.AsyncRequest<IPermissionController> {
private final @NonNull String mPackageName;
private final @NonNull String mPermissionName;
@@ -293,7 +270,7 @@
}
@Override
- public void run(IRuntimePermissionPresenter remoteInterface) {
+ public void run(IPermissionController remoteInterface) {
try {
remoteInterface.revokeRuntimePermission(mPackageName, mPermissionName);
} catch (RemoteException e) {
@@ -306,7 +283,7 @@
* Request for {@link #countPermissionApps}
*/
private static final class PendingCountPermissionAppsRequest extends
- AbstractRemoteService.PendingRequest<RemoteService, IRuntimePermissionPresenter> {
+ AbstractRemoteService.PendingRequest<RemoteService, IPermissionController> {
private final @NonNull List<String> mPermissionNames;
private final @NonNull OnCountPermissionAppsResultCallback mCallback;
private final boolean mCountOnlyGranted;
diff --git a/core/java/android/permission/RuntimePermissionPresenterService.java b/core/java/android/permission/PermissionControllerService.java
similarity index 76%
rename from core/java/android/permission/RuntimePermissionPresenterService.java
rename to core/java/android/permission/PermissionControllerService.java
index 81ec7be..5dad071 100644
--- a/core/java/android/permission/RuntimePermissionPresenterService.java
+++ b/core/java/android/permission/PermissionControllerService.java
@@ -20,6 +20,7 @@
import static com.android.internal.util.Preconditions.checkNotNull;
import static com.android.internal.util.function.pooled.PooledLambda.obtainMessage;
+import android.Manifest;
import android.annotation.NonNull;
import android.annotation.SystemApi;
import android.app.Service;
@@ -33,26 +34,21 @@
import java.util.List;
/**
- * This service presents information regarding runtime permissions that is
- * used for presenting them in the UI. Runtime permissions are presented as
- * a single permission in the UI but may be composed of several individual
- * permissions.
+ * This service is meant to be implemented by the app controlling permissions.
*
- * @see RuntimePermissionPresenter
- * @see RuntimePermissionPresentationInfo
+ * @see PermissionController
*
* @hide
*/
@SystemApi
-public abstract class RuntimePermissionPresenterService extends Service {
+public abstract class PermissionControllerService extends Service {
/**
* The {@link Intent} action that must be declared as handled by a service
* in its manifest for the system to recognize it as a runtime permission
* presenter service.
*/
- public static final String SERVICE_INTERFACE =
- "android.permission.RuntimePermissionPresenterService";
+ public static final String SERVICE_INTERFACE = "android.permission.PermissionControllerService";
// No need for locking - always set first and never modified
private Handler mHandler;
@@ -96,16 +92,17 @@
@Override
public final IBinder onBind(Intent intent) {
- return new IRuntimePermissionPresenter.Stub() {
+ return new IPermissionController.Stub() {
@Override
public void getAppPermissions(String packageName, RemoteCallback callback) {
checkNotNull(packageName, "packageName");
checkNotNull(callback, "callback");
+ enforceCallingPermission(Manifest.permission.GET_RUNTIME_PERMISSIONS, null);
+
mHandler.sendMessage(
- obtainMessage(
- RuntimePermissionPresenterService::getAppPermissions,
- RuntimePermissionPresenterService.this, packageName, callback));
+ obtainMessage(PermissionControllerService::getAppPermissions,
+ PermissionControllerService.this, packageName, callback));
}
@Override
@@ -113,11 +110,11 @@
checkNotNull(packageName, "packageName");
checkNotNull(permissionName, "permissionName");
+ enforceCallingPermission(Manifest.permission.REVOKE_RUNTIME_PERMISSIONS, null);
+
mHandler.sendMessage(
- obtainMessage(
- RuntimePermissionPresenterService::onRevokeRuntimePermission,
- RuntimePermissionPresenterService.this, packageName,
- permissionName));
+ obtainMessage(PermissionControllerService::onRevokeRuntimePermission,
+ PermissionControllerService.this, packageName, permissionName));
}
@Override
@@ -126,11 +123,12 @@
checkCollectionElementsNotNull(permissionNames, "permissionNames");
checkNotNull(callback, "callback");
+ enforceCallingPermission(Manifest.permission.GET_RUNTIME_PERMISSIONS, null);
+
mHandler.sendMessage(
- obtainMessage(
- RuntimePermissionPresenterService::countPermissionApps,
- RuntimePermissionPresenterService.this, permissionNames,
- countOnlyGranted, countSystem, callback));
+ obtainMessage(PermissionControllerService::countPermissionApps,
+ PermissionControllerService.this, permissionNames, countOnlyGranted,
+ countSystem, callback));
}
};
}
@@ -139,7 +137,7 @@
List<RuntimePermissionPresentationInfo> permissions = onGetAppPermissions(packageName);
if (permissions != null && !permissions.isEmpty()) {
Bundle result = new Bundle();
- result.putParcelableList(RuntimePermissionPresenter.KEY_RESULT, permissions);
+ result.putParcelableList(PermissionControllerManager.KEY_RESULT, permissions);
callback.sendResult(result);
} else {
callback.sendResult(null);
@@ -151,7 +149,7 @@
int numApps = onCountPermissionApps(permissionNames, countOnlyGranted, countSystem);
Bundle result = new Bundle();
- result.putInt(RuntimePermissionPresenter.KEY_RESULT, numApps);
+ result.putInt(PermissionControllerManager.KEY_RESULT, numApps);
callback.sendResult(result);
}
}
diff --git a/core/java/android/permissionpresenterservice/RuntimePermissionPresenterService.java b/core/java/android/permissionpresenterservice/RuntimePermissionPresenterService.java
index 2b3f0f5..8d568c8 100644
--- a/core/java/android/permissionpresenterservice/RuntimePermissionPresenterService.java
+++ b/core/java/android/permissionpresenterservice/RuntimePermissionPresenterService.java
@@ -30,6 +30,7 @@
import android.os.Handler;
import android.os.IBinder;
import android.os.RemoteCallback;
+import android.permission.PermissionControllerService;
import java.util.List;
@@ -43,7 +44,7 @@
*
* @hide
*
- * @deprecated use {@link android.permission.RuntimePermissionPresenterService} instead
+ * @deprecated use {@link PermissionControllerService} instead
*/
@Deprecated
@SystemApi
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index 52effb3..bb1784a 100644
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -14075,11 +14075,10 @@
try {
Bundle arg = new Bundle();
arg.putInt(CALL_METHOD_USER_KEY, resolver.getUserId());
- arg.putInt(Settings.CALL_METHOD_RESET_MODE_KEY, resetMode);
+ arg.putInt(CALL_METHOD_RESET_MODE_KEY, resetMode);
if (prefix != null) {
arg.putString(Settings.CALL_METHOD_PREFIX_KEY, prefix);
}
- arg.putInt(CALL_METHOD_RESET_MODE_KEY, resetMode);
IContentProvider cp = sProviderHolder.getProvider(resolver);
cp.call(resolver.getPackageName(), sProviderHolder.mUri.getAuthority(),
CALL_METHOD_RESET_CONFIG, null, arg);
diff --git a/core/java/android/view/InsetsState.java b/core/java/android/view/InsetsState.java
index 3f8f882..885b3e9 100644
--- a/core/java/android/view/InsetsState.java
+++ b/core/java/android/view/InsetsState.java
@@ -250,7 +250,7 @@
}
}
- static String typeToString(int type) {
+ public static String typeToString(int type) {
switch (type) {
case TYPE_TOP_BAR:
return "TYPE_TOP_BAR";
diff --git a/core/java/android/view/contentcapture/ContentCaptureSession.java b/core/java/android/view/contentcapture/ContentCaptureSession.java
index fb6cacf..46e6882 100644
--- a/core/java/android/view/contentcapture/ContentCaptureSession.java
+++ b/core/java/android/view/contentcapture/ContentCaptureSession.java
@@ -42,6 +42,8 @@
*/
public abstract class ContentCaptureSession implements AutoCloseable {
+ private static final String TAG = ContentCaptureSession.class.getSimpleName();
+
/**
* Used on {@link #notifyViewTextChanged(AutofillId, CharSequence, int)} to indicate that the
*
@@ -86,9 +88,6 @@
private static final int INITIAL_CHILDREN_CAPACITY = 5;
- /** @hide */
- protected final String mTag = getClass().getSimpleName();
-
private final CloseGuard mCloseGuard = CloseGuard.get();
/**
@@ -141,7 +140,7 @@
@NonNull ContentCaptureContext context) {
final ContentCaptureSession child = newChild(context);
if (DEBUG) {
- Log.d(mTag, "createContentCaptureSession(" + context + ": parent=" + mId + ", child= "
+ Log.d(TAG, "createContentCaptureSession(" + context + ": parent=" + mId + ", child="
+ child.mId);
}
if (mChildren == null) {
@@ -165,7 +164,7 @@
*/
public final void destroy() {
if (!mDestroyed.compareAndSet(false, true)) {
- Log.e(mTag, "destroy(): already destroyed");
+ Log.e(TAG, "destroy(): already destroyed");
return;
}
@@ -174,19 +173,19 @@
//TODO(b/111276913): check state (for example, how to handle if it's waiting for remote
// id) and send it to the cache of batched commands
if (VERBOSE) {
- Log.v(mTag, "destroy(): state=" + getStateAsString(mState) + ", mId=" + mId);
+ Log.v(TAG, "destroy(): state=" + getStateAsString(mState) + ", mId=" + mId);
}
// Finish children first
if (mChildren != null) {
final int numberChildren = mChildren.size();
- if (VERBOSE) Log.v(mTag, "Destroying " + numberChildren + " children first");
+ if (VERBOSE) Log.v(TAG, "Destroying " + numberChildren + " children first");
for (int i = 0; i < numberChildren; i++) {
final ContentCaptureSession child = mChildren.get(i);
try {
child.destroy();
} catch (Exception e) {
- Log.w(mTag, "exception destroying child session #" + i + ": " + e);
+ Log.w(TAG, "exception destroying child session #" + i + ": " + e);
}
}
}
@@ -311,11 +310,12 @@
@CallSuper
void dump(@NonNull String prefix, @NonNull PrintWriter pw) {
+ pw.print(prefix); pw.print("id: "); pw.println(mId);
pw.print(prefix); pw.print("destroyed: "); pw.println(mDestroyed.get());
if (mChildren != null && !mChildren.isEmpty()) {
final String prefix2 = prefix + " ";
final int numberChildren = mChildren.size();
- pw.print(prefix); pw.print("number children: "); pw.print(numberChildren);
+ pw.print(prefix); pw.print("number children: "); pw.println(numberChildren);
for (int i = 0; i < numberChildren; i++) {
final ContentCaptureSession child = mChildren.get(i);
pw.print(prefix); pw.print(i); pw.println(": "); child.dump(prefix2, pw);
diff --git a/core/java/android/view/contentcapture/MainContentCaptureSession.java b/core/java/android/view/contentcapture/MainContentCaptureSession.java
index 12c50ce..baf4a35 100644
--- a/core/java/android/view/contentcapture/MainContentCaptureSession.java
+++ b/core/java/android/view/contentcapture/MainContentCaptureSession.java
@@ -63,6 +63,8 @@
*/
public final class MainContentCaptureSession extends ContentCaptureSession {
+ private static final String TAG = MainContentCaptureSession.class.getSimpleName();
+
/**
* Handler message used to flush the buffer.
*/
@@ -128,9 +130,6 @@
// Used just for debugging purposes (on dump)
private long mNextFlush;
- // Lazily created on demand.
- private ContentCaptureSessionId mContentCaptureSessionId;
-
/** @hide */
protected MainContentCaptureSession(@NonNull Context context, @NonNull Handler handler,
@Nullable IContentCaptureManager systemServerInterface,
@@ -157,7 +156,7 @@
if (!isContentCaptureEnabled()) return;
if (VERBOSE) {
- Log.v(mTag, "start(): token=" + applicationToken + ", comp="
+ Log.v(TAG, "start(): token=" + applicationToken + ", comp="
+ ComponentName.flattenToShortString(activityComponent));
}
@@ -179,7 +178,7 @@
private void handleStartSession(@NonNull IBinder token, @NonNull ComponentName componentName) {
if (mState != STATE_UNKNOWN) {
// TODO(b/111276913): revisit this scenario
- Log.w(mTag, "ignoring handleStartSession(" + token + ") while on state "
+ Log.w(TAG, "ignoring handleStartSession(" + token + ") while on state "
+ getStateAsString(mState));
return;
}
@@ -188,7 +187,7 @@
mComponentName = componentName;
if (VERBOSE) {
- Log.v(mTag, "handleStartSession(): token=" + token + ", act="
+ Log.v(TAG, "handleStartSession(): token=" + token + ", act="
+ getActivityDebugName() + ", id=" + mId);
}
final int flags = 0; // TODO(b/111276913): get proper flags
@@ -202,7 +201,7 @@
if (resultData != null) {
binder = resultData.getBinder(EXTRA_BINDER);
if (binder == null) {
- Log.wtf(mTag, "No " + EXTRA_BINDER + " extra result");
+ Log.wtf(TAG, "No " + EXTRA_BINDER + " extra result");
handleResetState();
return;
}
@@ -211,7 +210,7 @@
}
});
} catch (RemoteException e) {
- Log.w(mTag, "Error starting session for " + componentName.flattenToShortString() + ": "
+ Log.w(TAG, "Error starting session for " + componentName.flattenToShortString() + ": "
+ e);
}
}
@@ -229,13 +228,13 @@
if (binder != null) {
mDirectServiceInterface = IContentCaptureDirectManager.Stub.asInterface(binder);
mDirectServiceVulture = () -> {
- Log.w(mTag, "Destroying session " + mId + " because service died");
+ Log.w(TAG, "Destroying session " + mId + " because service died");
destroy();
};
try {
binder.linkToDeath(mDirectServiceVulture, 0);
} catch (RemoteException e) {
- Log.w(mTag, "Failed to link to death on " + binder + ": " + e);
+ Log.w(TAG, "Failed to link to death on " + binder + ": " + e);
}
}
if (resultCode == STATE_DISABLED || resultCode == STATE_DISABLED_DUPLICATED_ID) {
@@ -245,7 +244,7 @@
mDisabled.set(false);
}
if (VERBOSE) {
- Log.v(mTag, "handleSessionStarted() result: code=" + resultCode + ", id=" + mId
+ Log.v(TAG, "handleSessionStarted() result: code=" + resultCode + ", id=" + mId
+ ", state=" + getStateAsString(mState) + ", disabled=" + mDisabled.get()
+ ", binder=" + binder);
}
@@ -254,7 +253,7 @@
private void handleSendEvent(@NonNull ContentCaptureEvent event, boolean forceFlush) {
if (mEvents == null) {
if (VERBOSE) {
- Log.v(mTag, "Creating buffer for " + MAX_BUFFER_SIZE + " events");
+ Log.v(TAG, "Creating buffer for " + MAX_BUFFER_SIZE + " events");
}
mEvents = new ArrayList<>(MAX_BUFFER_SIZE);
}
@@ -266,7 +265,7 @@
if (lastEvent.getType() == TYPE_VIEW_TEXT_CHANGED
&& lastEvent.getId().equals(event.getId())) {
if (VERBOSE) {
- Log.v(mTag, "Buffering VIEW_TEXT_CHANGED event, updated text = "
+ Log.v(TAG, "Buffering VIEW_TEXT_CHANGED event, updated text = "
+ event.getText());
}
lastEvent.setText(event.getText());
@@ -293,7 +292,7 @@
// not complete instead. Similarly, the manager service should return right away
// when the user does not have a service set
if (VERBOSE) {
- Log.v(mTag, "Closing session for " + getActivityDebugName()
+ Log.v(TAG, "Closing session for " + getActivityDebugName()
+ " after " + numberEvents + " delayed events and state "
+ getStateAsString(mState));
}
@@ -313,7 +312,7 @@
}
mNextFlush = SystemClock.elapsedRealtime() + FLUSHING_FREQUENCY_MS;
if (VERBOSE) {
- Log.v(mTag, "Scheduled to flush in " + FLUSHING_FREQUENCY_MS + "ms: " + mNextFlush);
+ Log.v(TAG, "Scheduled to flush in " + FLUSHING_FREQUENCY_MS + "ms: " + mNextFlush);
}
mHandler.sendMessageDelayed(
obtainMessage(MainContentCaptureSession::handleFlushIfNeeded, this)
@@ -322,7 +321,7 @@
private void handleFlushIfNeeded() {
if (mEvents.isEmpty()) {
- if (VERBOSE) Log.v(mTag, "Nothing to flush");
+ if (VERBOSE) Log.v(TAG, "Nothing to flush");
return;
}
handleForceFlush();
@@ -332,7 +331,7 @@
if (mEvents == null) return;
if (mDirectServiceInterface == null) {
- if (DEBUG) Log.d(mTag, "handleForceFlush(): hold your horses, client not ready yet!");
+ if (DEBUG) Log.d(TAG, "handleForceFlush(): hold your horses, client not ready yet!");
if (!mHandler.hasMessages(MSG_FLUSH)) {
handleScheduleFlush(/* checkExisting= */ false);
}
@@ -342,14 +341,14 @@
final int numberEvents = mEvents.size();
try {
if (DEBUG) {
- Log.d(mTag, "Flushing " + numberEvents + " event(s) for " + getActivityDebugName());
+ Log.d(TAG, "Flushing " + numberEvents + " event(s) for " + getActivityDebugName());
}
mHandler.removeMessages(MSG_FLUSH);
final ParceledListSlice<ContentCaptureEvent> events = handleClearEvents();
mDirectServiceInterface.sendEvents(events);
} catch (RemoteException e) {
- Log.w(mTag, "Error sending " + numberEvents + " for " + getActivityDebugName()
+ Log.w(TAG, "Error sending " + numberEvents + " for " + getActivityDebugName()
+ ": " + e);
}
}
@@ -370,7 +369,7 @@
private void handleDestroySession() {
if (DEBUG) {
- Log.d(mTag, "Destroying session (ctx=" + mContext + ", id=" + mId + ") with "
+ Log.d(TAG, "Destroying session (ctx=" + mContext + ", id=" + mId + ") with "
+ (mEvents == null ? 0 : mEvents.size()) + " event(s) for "
+ getActivityDebugName());
}
@@ -378,7 +377,7 @@
try {
mSystemServerInterface.finishSession(mContext.getUserId(), mId);
} catch (RemoteException e) {
- Log.e(mTag, "Error destroying system-service session " + mId + " for "
+ Log.e(TAG, "Error destroying system-service session " + mId + " for "
+ getActivityDebugName() + ": " + e);
}
}
@@ -395,8 +394,6 @@
}
// TODO(b/121033016): must reset children (which currently is owned by superclass)
-
- mContentCaptureSessionId = null;
mApplicationToken = null;
mComponentName = null;
mEvents = null;
@@ -482,9 +479,6 @@
}
pw.print(prefix); pw.print("mDisabled: "); pw.println(mDisabled.get());
pw.print(prefix); pw.print("isEnabled(): "); pw.println(isContentCaptureEnabled());
- if (mContentCaptureSessionId != null) {
- pw.print(prefix); pw.print("public id: "); pw.println(mContentCaptureSessionId);
- }
pw.print(prefix); pw.print("state: "); pw.print(mState); pw.print(" (");
pw.print(getStateAsString(mState)); pw.println(")");
if (mApplicationToken != null) {
diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml
index be37ca9..0778304 100644
--- a/core/res/AndroidManifest.xml
+++ b/core/res/AndroidManifest.xml
@@ -3379,6 +3379,11 @@
<permission android:name="android.permission.REVOKE_RUNTIME_PERMISSIONS"
android:protectionLevel="signature|installer|verifier" />
+ <!-- @SystemApi Allows the system to read runtime permission state.
+ @hide -->
+ <permission android:name="android.permission.GET_RUNTIME_PERMISSIONS"
+ android:protectionLevel="signature" />
+
<!-- @hide Allows an application to observe permission changes. -->
<permission android:name="android.permission.OBSERVE_GRANT_REVOKE_PERMISSIONS"
android:protectionLevel="signature|privileged" />
diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml
index 91faa55..183c2e8 100644
--- a/core/res/res/values/attrs.xml
+++ b/core/res/res/values/attrs.xml
@@ -3755,6 +3755,8 @@
<!-- Component name of an activity that allows the user to modify
the settings for this service. -->
<attr name="settingsActivity"/>
+ <!-- Secure Element which the AIDs should be routed to -->
+ <attr name="secureElementName"/>
</declare-styleable>
<!-- Specify one or more <code>aid-group</code> elements inside a
diff --git a/packages/CarSystemUI/src/com/android/systemui/CarSystemUIFactory.java b/packages/CarSystemUI/src/com/android/systemui/CarSystemUIFactory.java
index 3c0a297..0c35204 100644
--- a/packages/CarSystemUI/src/com/android/systemui/CarSystemUIFactory.java
+++ b/packages/CarSystemUI/src/com/android/systemui/CarSystemUIFactory.java
@@ -20,11 +20,9 @@
import com.android.internal.widget.LockPatternUtils;
import com.android.keyguard.ViewMediatorCallback;
-import com.android.systemui.car.CarNotificationEntryManager;
import com.android.systemui.car.CarNotificationInterruptionStateProvider;
import com.android.systemui.statusbar.car.CarFacetButtonController;
import com.android.systemui.statusbar.car.CarStatusBarKeyguardViewManager;
-import com.android.systemui.statusbar.notification.NotificationEntryManager;
import com.android.systemui.statusbar.notification.NotificationInterruptionStateProvider;
import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager;
import com.android.systemui.volume.CarVolumeDialogComponent;
@@ -65,16 +63,16 @@
}
@Override
- public NotificationEntryManager provideNotificationEntryManager(Context context) {
- return new CarNotificationEntryManager(context);
- }
-
- @Override
public NotificationInterruptionStateProvider provideNotificationInterruptionStateProvider(
Context context) {
return new CarNotificationInterruptionStateProvider(context);
}
+ @Override
+ public boolean provideAllowNotificationLongPress() {
+ return false;
+ }
+
@Module
protected static class ContextHolder {
private Context mContext;
diff --git a/packages/CarSystemUI/src/com/android/systemui/car/CarNotificationEntryManager.java b/packages/CarSystemUI/src/com/android/systemui/car/CarNotificationEntryManager.java
deleted file mode 100644
index 323cae0..0000000
--- a/packages/CarSystemUI/src/com/android/systemui/car/CarNotificationEntryManager.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (C) 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.systemui.car;
-
-import android.content.Context;
-
-import com.android.systemui.statusbar.notification.NotificationEntryManager;
-import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
-
-public class CarNotificationEntryManager extends NotificationEntryManager {
- public CarNotificationEntryManager(Context context) {
- super(context);
- }
-
- /**
- * Returns the
- * {@link ExpandableNotificationRow.LongPressListener} that will
- * be triggered when a notification card is long-pressed.
- */
- @Override
- public ExpandableNotificationRow.LongPressListener getNotificationLongClicker() {
- // For the automative use case, we do not want to the user to be able to interact with
- // a notification other than a regular click. As a result, just return null for the
- // long click listener.
- return null;
- }
-}
diff --git a/packages/SettingsLib/src/com/android/settingslib/applications/PermissionsSummaryHelper.java b/packages/SettingsLib/src/com/android/settingslib/applications/PermissionsSummaryHelper.java
index 2387b01..5e5c22a 100644
--- a/packages/SettingsLib/src/com/android/settingslib/applications/PermissionsSummaryHelper.java
+++ b/packages/SettingsLib/src/com/android/settingslib/applications/PermissionsSummaryHelper.java
@@ -16,8 +16,8 @@
package com.android.settingslib.applications;
import android.content.Context;
+import android.permission.PermissionControllerManager;
import android.permission.RuntimePermissionPresentationInfo;
-import android.permission.RuntimePermissionPresenter;
import java.text.Collator;
import java.util.ArrayList;
@@ -28,9 +28,9 @@
public static void getPermissionSummary(Context context, String pkg,
final PermissionsResultCallback callback) {
- final RuntimePermissionPresenter presenter =
- RuntimePermissionPresenter.getInstance(context);
- presenter.getAppPermissions(pkg, permissions -> {
+ final PermissionControllerManager permController =
+ context.getSystemService(PermissionControllerManager.class);
+ permController.getAppPermissions(pkg, permissions -> {
final int permissionCount = permissions.size();
int grantedStandardCount = 0;
diff --git a/packages/SettingsProvider/src/com/android/providers/settings/DeviceConfigService.java b/packages/SettingsProvider/src/com/android/providers/settings/DeviceConfigService.java
index f2b2719..d0ffe7a 100644
--- a/packages/SettingsProvider/src/com/android/providers/settings/DeviceConfigService.java
+++ b/packages/SettingsProvider/src/com/android/providers/settings/DeviceConfigService.java
@@ -242,7 +242,7 @@
Bundle args = new Bundle();
args.putInt(Settings.CALL_METHOD_USER_KEY,
ActivityManager.getService().getCurrentUser().id);
- Bundle b = provider.call(resolveCallingPackage(),
+ Bundle b = provider.call(resolveCallingPackage(), Settings.AUTHORITY,
Settings.CALL_METHOD_DELETE_CONFIG, compositeKey, args);
success = (b != null && b.getInt(SettingsProvider.RESULT_ROWS_DELETED) == 1);
} catch (RemoteException e) {
@@ -261,7 +261,7 @@
if (namespace != null) {
args.putString(Settings.CALL_METHOD_PREFIX_KEY, namespace);
}
- Bundle b = provider.call(resolveCallingPackage(),
+ Bundle b = provider.call(resolveCallingPackage(), Settings.AUTHORITY,
Settings.CALL_METHOD_LIST_CONFIG, null, args);
if (b != null) {
Map<String, String> flagsToValues =
diff --git a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java
index 1727e75..bce5593 100644
--- a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java
+++ b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java
@@ -1097,7 +1097,7 @@
case MUTATION_OPERATION_INSERT: {
return mSettingsRegistry.insertSettingLocked(SETTINGS_TYPE_CONFIG,
UserHandle.USER_SYSTEM, name, value, null, makeDefault, true,
- getCallingPackage(), false, null);
+ resolveCallingPackage(), false, null);
}
case MUTATION_OPERATION_DELETE: {
@@ -1107,7 +1107,7 @@
case MUTATION_OPERATION_RESET: {
mSettingsRegistry.resetSettingsLocked(SETTINGS_TYPE_CONFIG,
- UserHandle.USER_SYSTEM, getCallingPackage(), mode, null, prefix);
+ UserHandle.USER_SYSTEM, resolveCallingPackage(), mode, null, prefix);
} return true;
}
}
@@ -2247,6 +2247,22 @@
return !(TextUtils.isEmpty(key) || SettingsState.isBinary(key));
}
+ private String resolveCallingPackage() {
+ switch (Binder.getCallingUid()) {
+ case Process.ROOT_UID: {
+ return "root";
+ }
+
+ case Process.SHELL_UID: {
+ return "com.android.shell";
+ }
+
+ default: {
+ return getCallingPackage();
+ }
+ }
+ }
+
private static final class Arguments {
private static final Pattern WHERE_PATTERN_WITH_PARAM_NO_BRACKETS =
Pattern.compile("[\\s]*name[\\s]*=[\\s]*\\?[\\s]*");
diff --git a/core/java/android/hardware/display/BrightnessCorrection.aidl b/packages/SystemUI/shared/src/com/android/systemui/shared/system/ContextCompat.java
similarity index 62%
rename from core/java/android/hardware/display/BrightnessCorrection.aidl
rename to packages/SystemUI/shared/src/com/android/systemui/shared/system/ContextCompat.java
index 3abe29c..51fcb0a 100644
--- a/core/java/android/hardware/display/BrightnessCorrection.aidl
+++ b/packages/SystemUI/shared/src/com/android/systemui/shared/system/ContextCompat.java
@@ -14,6 +14,21 @@
* limitations under the License.
*/
-package android.hardware.display;
+package com.android.systemui.shared.system;
-parcelable BrightnessCorrection;
+import android.content.Context;
+
+/**
+ * Wraps a context to expose some methods for launcher to call.
+ */
+public class ContextCompat {
+ private final Context mWrapped;
+
+ public ContextCompat(Context context) {
+ mWrapped = context;
+ }
+
+ public int getUserId() {
+ return mWrapped.getUserId();
+ }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/Dependency.java b/packages/SystemUI/src/com/android/systemui/Dependency.java
index a8d3763..3cc9bb6 100644
--- a/packages/SystemUI/src/com/android/systemui/Dependency.java
+++ b/packages/SystemUI/src/com/android/systemui/Dependency.java
@@ -157,6 +157,12 @@
public static final String LEAK_REPORT_EMAIL_NAME = "leak_report_email";
/**
+ * Whether this platform supports long-pressing notifications to show notification channel
+ * settings.
+ */
+ public static final String ALLOW_NOTIFICATION_LONG_PRESS_NAME = "allow_notif_longpress";
+
+ /**
* Key for getting a background Looper for background work.
*/
public static final DependencyKey<Looper> BG_LOOPER = new DependencyKey<>(BG_LOOPER_NAME);
@@ -272,6 +278,7 @@
Lazy<NotificationAlertingManager> mNotificationAlertingManager;
@Inject Lazy<SensorPrivacyManager> mSensorPrivacyManager;
@Inject Lazy<AutoHideController> mAutoHideController;
+ @Inject Lazy<ForegroundServiceNotificationListener> mForegroundServiceNotificationListener;
@Inject @Named(BG_LOOPER_NAME) Lazy<Looper> mBgLooper;
@Inject @Named(BG_HANDLER_NAME) Lazy<Handler> mBgHandler;
@Inject @Named(MAIN_HANDLER_NAME) Lazy<Handler> mMainHandler;
@@ -444,6 +451,8 @@
mProviders.put(BubbleController.class, mBubbleController::get);
mProviders.put(NotificationEntryManager.class, mNotificationEntryManager::get);
mProviders.put(NotificationAlertingManager.class, mNotificationAlertingManager::get);
+ mProviders.put(ForegroundServiceNotificationListener.class,
+ mForegroundServiceNotificationListener::get);
// TODO(b/118592525): to support multi-display , we start to add something which is
// per-display, while others may be global. I think it's time to add
diff --git a/packages/SystemUI/src/com/android/systemui/DependencyBinder.java b/packages/SystemUI/src/com/android/systemui/DependencyBinder.java
index 1ee1dcf..f324a05b 100644
--- a/packages/SystemUI/src/com/android/systemui/DependencyBinder.java
+++ b/packages/SystemUI/src/com/android/systemui/DependencyBinder.java
@@ -219,12 +219,6 @@
/**
*/
@Binds
- public abstract ForegroundServiceController provideForegroundService(
- ForegroundServiceControllerImpl controllerImpl);
-
- /**
- */
- @Binds
public abstract PowerUI.WarningsUI provideWarningsUi(PowerNotificationWarnings controllerImpl);
/**
diff --git a/packages/SystemUI/src/com/android/systemui/DependencyProvider.java b/packages/SystemUI/src/com/android/systemui/DependencyProvider.java
index dac977a..88e32cb 100644
--- a/packages/SystemUI/src/com/android/systemui/DependencyProvider.java
+++ b/packages/SystemUI/src/com/android/systemui/DependencyProvider.java
@@ -44,8 +44,6 @@
import com.android.systemui.statusbar.NavigationBarController;
import com.android.systemui.statusbar.phone.AutoHideController;
import com.android.systemui.statusbar.phone.ConfigurationControllerImpl;
-import com.android.systemui.statusbar.phone.ShadeController;
-import com.android.systemui.statusbar.phone.StatusBar;
import com.android.systemui.statusbar.policy.ConfigurationController;
import com.android.systemui.statusbar.policy.DataSaverController;
import com.android.systemui.statusbar.policy.NetworkController;
@@ -141,12 +139,6 @@
@Singleton
@Provides
- public ShadeController provideShadeController(Context context) {
- return SysUiServiceProvider.getComponent(context, StatusBar.class);
- }
-
- @Singleton
- @Provides
public SensorPrivacyManager provideSensorPrivacyManager(Context context) {
return context.getSystemService(SensorPrivacyManager.class);
}
diff --git a/packages/SystemUI/src/com/android/systemui/ForegroundServiceController.java b/packages/SystemUI/src/com/android/systemui/ForegroundServiceController.java
index ae6ee2a..df0d787 100644
--- a/packages/SystemUI/src/com/android/systemui/ForegroundServiceController.java
+++ b/packages/SystemUI/src/com/android/systemui/ForegroundServiceController.java
@@ -15,65 +15,158 @@
package com.android.systemui;
import android.annotation.Nullable;
+import android.os.UserHandle;
import android.service.notification.StatusBarNotification;
import android.util.ArraySet;
+import android.util.SparseArray;
-public interface ForegroundServiceController {
- /**
- * @param sbn notification that was just posted
- * @param importance
- */
- void addNotification(StatusBarNotification sbn, int importance);
+import com.android.internal.messages.nano.SystemMessageProto;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+/**
+ * Tracks state of foreground services and notifications related to foreground services per user.
+ */
+@Singleton
+public class ForegroundServiceController {
+
+ private final SparseArray<ForegroundServicesUserState> mUserServices = new SparseArray<>();
+ private final Object mMutex = new Object();
+
+ @Inject
+ public ForegroundServiceController() {
+ }
/**
- * @param sbn notification that was just changed in some way
- * @param newImportance
- */
- void updateNotification(StatusBarNotification sbn, int newImportance);
-
- /**
- * @param sbn notification that was just canceled
- */
- boolean removeNotification(StatusBarNotification sbn);
-
- /**
- * @param userId
* @return true if this user has services missing notifications and therefore needs a
* disclosure notification.
*/
- boolean isDungeonNeededForUser(int userId);
-
- /**
- * @param sbn
- * @return true if sbn is the system-provided "dungeon" (list of running foreground services).
- */
- boolean isDungeonNotification(StatusBarNotification sbn);
-
- /**
- * @return true if sbn is one of the window manager "drawing over other apps" notifications
- */
- boolean isSystemAlertNotification(StatusBarNotification sbn);
-
- /**
- * Returns the key of the foreground service from this package using the standard template,
- * if one exists.
- */
- @Nullable String getStandardLayoutKey(int userId, String pkg);
+ public boolean isDisclosureNeededForUser(int userId) {
+ synchronized (mMutex) {
+ final ForegroundServicesUserState services = mUserServices.get(userId);
+ if (services == null) return false;
+ return services.isDisclosureNeeded();
+ }
+ }
/**
* @return true if this user/pkg has a missing or custom layout notification and therefore needs
* a disclosure notification for system alert windows.
*/
- boolean isSystemAlertWarningNeeded(int userId, String pkg);
+ public boolean isSystemAlertWarningNeeded(int userId, String pkg) {
+ synchronized (mMutex) {
+ final ForegroundServicesUserState services = mUserServices.get(userId);
+ if (services == null) return false;
+ return services.getStandardLayoutKey(pkg) == null;
+ }
+ }
+
+ /**
+ * Returns the key of the foreground service from this package using the standard template,
+ * if one exists.
+ */
+ @Nullable
+ public String getStandardLayoutKey(int userId, String pkg) {
+ synchronized (mMutex) {
+ final ForegroundServicesUserState services = mUserServices.get(userId);
+ if (services == null) return null;
+ return services.getStandardLayoutKey(pkg);
+ }
+ }
+
+ /**
+ * Gets active app ops for this user and package
+ */
+ @Nullable
+ public ArraySet<Integer> getAppOps(int userId, String pkg) {
+ synchronized (mMutex) {
+ final ForegroundServicesUserState services = mUserServices.get(userId);
+ if (services == null) {
+ return null;
+ }
+ return services.getFeatures(pkg);
+ }
+ }
/**
* Records active app ops. App Ops are stored in FSC in addition to NotificationData in
* case they change before we have a notification to tag.
*/
- void onAppOpChanged(int code, int uid, String packageName, boolean active);
+ public void onAppOpChanged(int code, int uid, String packageName, boolean active) {
+ int userId = UserHandle.getUserId(uid);
+ synchronized (mMutex) {
+ ForegroundServicesUserState userServices = mUserServices.get(userId);
+ if (userServices == null) {
+ userServices = new ForegroundServicesUserState();
+ mUserServices.put(userId, userServices);
+ }
+ if (active) {
+ userServices.addOp(packageName, code);
+ } else {
+ userServices.removeOp(packageName, code);
+ }
+ }
+ }
/**
- * Gets active app ops for this user and package
+ * Looks up the {@link ForegroundServicesUserState} for the given {@code userId}, then performs
+ * the given {@link UserStateUpdateCallback} on it. If no state exists for the user ID, creates
+ * a new one if {@code createIfNotFound} is true, then performs the update on the new state.
+ * If {@code createIfNotFound} is false, no update is performed.
+ *
+ * @return false if no user state was found and none was created; true otherwise.
*/
- @Nullable ArraySet<Integer> getAppOps(int userId, String packageName);
+ boolean updateUserState(int userId,
+ UserStateUpdateCallback updateCallback,
+ boolean createIfNotFound) {
+ synchronized (mMutex) {
+ ForegroundServicesUserState userState = mUserServices.get(userId);
+ if (userState == null) {
+ if (createIfNotFound) {
+ userState = new ForegroundServicesUserState();
+ mUserServices.put(userId, userState);
+ } else {
+ return false;
+ }
+ }
+ return updateCallback.updateUserState(userState);
+ }
+ }
+
+ /**
+ * @return true if {@code sbn} is the system-provided disclosure notification containing the
+ * list of running foreground services.
+ */
+ public boolean isDisclosureNotification(StatusBarNotification sbn) {
+ return sbn.getId() == SystemMessageProto.SystemMessage.NOTE_FOREGROUND_SERVICES
+ && sbn.getTag() == null
+ && sbn.getPackageName().equals("android");
+ }
+
+ /**
+ * @return true if sbn is one of the window manager "drawing over other apps" notifications
+ */
+ public boolean isSystemAlertNotification(StatusBarNotification sbn) {
+ return sbn.getPackageName().equals("android")
+ && sbn.getTag() != null
+ && sbn.getTag().contains("AlertWindowNotification");
+ }
+
+ /**
+ * Callback provided to {@link #updateUserState(int, UserStateUpdateCallback, boolean)}
+ * to perform the update.
+ */
+ interface UserStateUpdateCallback {
+ /**
+ * Perform update operations on the provided {@code userState}.
+ *
+ * @return true if the update succeeded.
+ */
+ boolean updateUserState(ForegroundServicesUserState userState);
+
+ /** Called if the state was not found and was not created. */
+ default void userStateNotFound(int userId) {
+ }
+ }
}
diff --git a/packages/SystemUI/src/com/android/systemui/ForegroundServiceControllerImpl.java b/packages/SystemUI/src/com/android/systemui/ForegroundServiceControllerImpl.java
deleted file mode 100644
index ae446dd..0000000
--- a/packages/SystemUI/src/com/android/systemui/ForegroundServiceControllerImpl.java
+++ /dev/null
@@ -1,309 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software distributed under the
- * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the specific language governing
- * permissions and limitations under the License.
- */
-
-package com.android.systemui;
-
-import android.app.Notification;
-import android.app.NotificationManager;
-import android.content.Context;
-import android.os.Bundle;
-import android.os.UserHandle;
-import android.service.notification.StatusBarNotification;
-import android.util.ArrayMap;
-import android.util.ArraySet;
-import android.util.Log;
-import android.util.SparseArray;
-
-import com.android.internal.messages.nano.SystemMessageProto;
-
-import java.util.Arrays;
-
-import javax.inject.Inject;
-import javax.inject.Singleton;
-
-/**
- * Foreground service controller, a/k/a Dianne's Dungeon.
- */
-@Singleton
-public class ForegroundServiceControllerImpl
- implements ForegroundServiceController {
-
- // shelf life of foreground services before they go bad
- public static final long FG_SERVICE_GRACE_MILLIS = 5000;
-
- private static final String TAG = "FgServiceController";
- private static final boolean DBG = false;
-
- private final Context mContext;
- private final SparseArray<UserServices> mUserServices = new SparseArray<>();
- private final Object mMutex = new Object();
-
- @Inject
- public ForegroundServiceControllerImpl(Context context) {
- mContext = context;
- }
-
- @Override
- public boolean isDungeonNeededForUser(int userId) {
- synchronized (mMutex) {
- final UserServices services = mUserServices.get(userId);
- if (services == null) return false;
- return services.isDungeonNeeded();
- }
- }
-
- @Override
- public boolean isSystemAlertWarningNeeded(int userId, String pkg) {
- synchronized (mMutex) {
- final UserServices services = mUserServices.get(userId);
- if (services == null) return false;
- return services.getStandardLayoutKey(pkg) == null;
- }
- }
-
- @Override
- public String getStandardLayoutKey(int userId, String pkg) {
- synchronized (mMutex) {
- final UserServices services = mUserServices.get(userId);
- if (services == null) return null;
- return services.getStandardLayoutKey(pkg);
- }
- }
-
- @Override
- public ArraySet<Integer> getAppOps(int userId, String pkg) {
- synchronized (mMutex) {
- final UserServices services = mUserServices.get(userId);
- if (services == null) {
- return null;
- }
- return services.getFeatures(pkg);
- }
- }
-
- @Override
- public void onAppOpChanged(int code, int uid, String packageName, boolean active) {
- int userId = UserHandle.getUserId(uid);
- synchronized (mMutex) {
- UserServices userServices = mUserServices.get(userId);
- if (userServices == null) {
- userServices = new UserServices();
- mUserServices.put(userId, userServices);
- }
- if (active) {
- userServices.addOp(packageName, code);
- } else {
- userServices.removeOp(packageName, code);
- }
- }
- }
-
- @Override
- public void addNotification(StatusBarNotification sbn, int importance) {
- updateNotification(sbn, importance);
- }
-
- @Override
- public boolean removeNotification(StatusBarNotification sbn) {
- synchronized (mMutex) {
- final UserServices userServices = mUserServices.get(sbn.getUserId());
- if (userServices == null) {
- if (DBG) {
- Log.w(TAG, String.format(
- "user %d with no known notifications got removeNotification for %s",
- sbn.getUserId(), sbn));
- }
- return false;
- }
- if (isDungeonNotification(sbn)) {
- // if you remove the dungeon entirely, we take that to mean there are
- // no running services
- userServices.setRunningServices(null, 0);
- return true;
- } else {
- // this is safe to call on any notification, not just FLAG_FOREGROUND_SERVICE
- return userServices.removeNotification(sbn.getPackageName(), sbn.getKey());
- }
- }
- }
-
- @Override
- public void updateNotification(StatusBarNotification sbn, int newImportance) {
- synchronized (mMutex) {
- UserServices userServices = mUserServices.get(sbn.getUserId());
- if (userServices == null) {
- userServices = new UserServices();
- mUserServices.put(sbn.getUserId(), userServices);
- }
-
- if (isDungeonNotification(sbn)) {
- final Bundle extras = sbn.getNotification().extras;
- if (extras != null) {
- final String[] svcs = extras.getStringArray(Notification.EXTRA_FOREGROUND_APPS);
- userServices.setRunningServices(svcs, sbn.getNotification().when);
- }
- } else {
- userServices.removeNotification(sbn.getPackageName(), sbn.getKey());
- if (0 != (sbn.getNotification().flags & Notification.FLAG_FOREGROUND_SERVICE)) {
- if (newImportance > NotificationManager.IMPORTANCE_MIN) {
- userServices.addImportantNotification(sbn.getPackageName(), sbn.getKey());
- }
- final Notification.Builder builder = Notification.Builder.recoverBuilder(
- mContext, sbn.getNotification());
- if (builder.usesStandardHeader()) {
- userServices.addStandardLayoutNotification(
- sbn.getPackageName(), sbn.getKey());
- }
- }
- }
- }
- }
-
- @Override
- public boolean isDungeonNotification(StatusBarNotification sbn) {
- return sbn.getId() == SystemMessageProto.SystemMessage.NOTE_FOREGROUND_SERVICES
- && sbn.getTag() == null
- && sbn.getPackageName().equals("android");
- }
-
- @Override
- public boolean isSystemAlertNotification(StatusBarNotification sbn) {
- return sbn.getPackageName().equals("android")
- && sbn.getTag() != null
- && sbn.getTag().contains("AlertWindowNotification");
- }
-
- /**
- * Struct to track relevant packages and notifications for a userid's foreground services.
- */
- private static class UserServices {
- private String[] mRunning = null;
- private long mServiceStartTime = 0;
- // package -> sufficiently important posted notification keys
- private ArrayMap<String, ArraySet<String>> mImportantNotifications = new ArrayMap<>(1);
- // package -> standard layout posted notification keys
- private ArrayMap<String, ArraySet<String>> mStandardLayoutNotifications = new ArrayMap<>(1);
-
- // package -> app ops
- private ArrayMap<String, ArraySet<Integer>> mAppOps = new ArrayMap<>(1);
-
- public void setRunningServices(String[] pkgs, long serviceStartTime) {
- mRunning = pkgs != null ? Arrays.copyOf(pkgs, pkgs.length) : null;
- mServiceStartTime = serviceStartTime;
- }
-
- public void addOp(String pkg, int op) {
- if (mAppOps.get(pkg) == null) {
- mAppOps.put(pkg, new ArraySet<>(3));
- }
- mAppOps.get(pkg).add(op);
- }
-
- public boolean removeOp(String pkg, int op) {
- final boolean found;
- final ArraySet<Integer> keys = mAppOps.get(pkg);
- if (keys == null) {
- found = false;
- } else {
- found = keys.remove(op);
- if (keys.size() == 0) {
- mAppOps.remove(pkg);
- }
- }
- return found;
- }
-
- public void addImportantNotification(String pkg, String key) {
- addNotification(mImportantNotifications, pkg, key);
- }
-
- public boolean removeImportantNotification(String pkg, String key) {
- return removeNotification(mImportantNotifications, pkg, key);
- }
-
- public void addStandardLayoutNotification(String pkg, String key) {
- addNotification(mStandardLayoutNotifications, pkg, key);
- }
-
- public boolean removeStandardLayoutNotification(String pkg, String key) {
- return removeNotification(mStandardLayoutNotifications, pkg, key);
- }
-
- public boolean removeNotification(String pkg, String key) {
- boolean removed = false;
- removed |= removeImportantNotification(pkg, key);
- removed |= removeStandardLayoutNotification(pkg, key);
- return removed;
- }
-
- public void addNotification(ArrayMap<String, ArraySet<String>> map, String pkg,
- String key) {
- if (map.get(pkg) == null) {
- map.put(pkg, new ArraySet<>());
- }
- map.get(pkg).add(key);
- }
-
- public boolean removeNotification(ArrayMap<String, ArraySet<String>> map,
- String pkg, String key) {
- final boolean found;
- final ArraySet<String> keys = map.get(pkg);
- if (keys == null) {
- found = false;
- } else {
- found = keys.remove(key);
- if (keys.size() == 0) {
- map.remove(pkg);
- }
- }
- return found;
- }
-
- public boolean isDungeonNeeded() {
- if (mRunning != null
- && System.currentTimeMillis() - mServiceStartTime >= FG_SERVICE_GRACE_MILLIS) {
-
- for (String pkg : mRunning) {
- final ArraySet<String> set = mImportantNotifications.get(pkg);
- if (set == null || set.size() == 0) {
- return true;
- }
- }
- }
- return false;
- }
-
- public ArraySet<Integer> getFeatures(String pkg) {
- return mAppOps.get(pkg);
- }
-
- public String getStandardLayoutKey(String pkg) {
- final ArraySet<String> set = mStandardLayoutNotifications.get(pkg);
- if (set == null || set.size() == 0) {
- return null;
- }
- return set.valueAt(0);
- }
-
- @Override
- public String toString() {
- return "UserServices{" +
- "mRunning=" + Arrays.toString(mRunning) +
- ", mServiceStartTime=" + mServiceStartTime +
- ", mImportantNotifications=" + mImportantNotifications +
- ", mStandardLayoutNotifications=" + mStandardLayoutNotifications +
- '}';
- }
- }
-}
diff --git a/packages/SystemUI/src/com/android/systemui/ForegroundServiceNotificationListener.java b/packages/SystemUI/src/com/android/systemui/ForegroundServiceNotificationListener.java
new file mode 100644
index 0000000..151a6b0
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/ForegroundServiceNotificationListener.java
@@ -0,0 +1,152 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui;
+
+import android.app.Notification;
+import android.app.NotificationManager;
+import android.content.Context;
+import android.os.Bundle;
+import android.service.notification.StatusBarNotification;
+import android.util.Log;
+
+import com.android.internal.statusbar.NotificationVisibility;
+import com.android.systemui.statusbar.notification.NotificationData;
+import com.android.systemui.statusbar.notification.NotificationEntryListener;
+import com.android.systemui.statusbar.notification.NotificationEntryManager;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+/** Updates foreground service notification state in response to notification data events. */
+@Singleton
+public class ForegroundServiceNotificationListener {
+
+ private static final String TAG = "FgServiceController";
+ private static final boolean DBG = false;
+
+ private final Context mContext;
+ private final ForegroundServiceController mForegroundServiceController;
+
+ @Inject
+ public ForegroundServiceNotificationListener(Context context,
+ ForegroundServiceController foregroundServiceController,
+ NotificationEntryManager notificationEntryManager) {
+ mContext = context;
+ mForegroundServiceController = foregroundServiceController;
+ notificationEntryManager.addNotificationEntryListener(new NotificationEntryListener() {
+ @Override
+ public void onPendingEntryAdded(NotificationData.Entry entry) {
+ addNotification(entry.notification, entry.importance);
+ }
+
+ @Override
+ public void onEntryUpdated(NotificationData.Entry entry) {
+ updateNotification(entry.notification, entry.importance);
+ }
+
+ @Override
+ public void onEntryRemoved(
+ NotificationData.Entry entry,
+ String key,
+ StatusBarNotification old,
+ NotificationVisibility visibility,
+ boolean lifetimeExtended,
+ boolean removedByUser) {
+ if (entry != null && !lifetimeExtended) {
+ removeNotification(entry.notification);
+ }
+ }
+ });
+ }
+
+ /**
+ * @param sbn notification that was just posted
+ */
+ private void addNotification(StatusBarNotification sbn, int importance) {
+ updateNotification(sbn, importance);
+ }
+
+ /**
+ * @param sbn notification that was just removed
+ */
+ private void removeNotification(StatusBarNotification sbn) {
+ mForegroundServiceController.updateUserState(
+ sbn.getUserId(),
+ new ForegroundServiceController.UserStateUpdateCallback() {
+ @Override
+ public boolean updateUserState(ForegroundServicesUserState userState) {
+ if (mForegroundServiceController.isDisclosureNotification(sbn)) {
+ // if you remove the dungeon entirely, we take that to mean there are
+ // no running services
+ userState.setRunningServices(null, 0);
+ return true;
+ } else {
+ // this is safe to call on any notification, not just
+ // FLAG_FOREGROUND_SERVICE
+ return userState.removeNotification(sbn.getPackageName(), sbn.getKey());
+ }
+ }
+
+ @Override
+ public void userStateNotFound(int userId) {
+ if (DBG) {
+ Log.w(TAG, String.format(
+ "user %d with no known notifications got removeNotification "
+ + "for %s",
+ sbn.getUserId(), sbn));
+ }
+ }
+ },
+ false /* don't create */);
+ }
+
+ /**
+ * @param sbn notification that was just changed in some way
+ */
+ private void updateNotification(StatusBarNotification sbn, int newImportance) {
+ mForegroundServiceController.updateUserState(
+ sbn.getUserId(),
+ userState -> {
+ if (mForegroundServiceController.isDisclosureNotification(sbn)) {
+ final Bundle extras = sbn.getNotification().extras;
+ if (extras != null) {
+ final String[] svcs = extras.getStringArray(
+ Notification.EXTRA_FOREGROUND_APPS);
+ userState.setRunningServices(svcs, sbn.getNotification().when);
+ }
+ } else {
+ userState.removeNotification(sbn.getPackageName(), sbn.getKey());
+ if (0 != (sbn.getNotification().flags
+ & Notification.FLAG_FOREGROUND_SERVICE)) {
+ if (newImportance > NotificationManager.IMPORTANCE_MIN) {
+ userState.addImportantNotification(sbn.getPackageName(),
+ sbn.getKey());
+ }
+ final Notification.Builder builder =
+ Notification.Builder.recoverBuilder(
+ mContext, sbn.getNotification());
+ if (builder.usesStandardHeader()) {
+ userState.addStandardLayoutNotification(
+ sbn.getPackageName(), sbn.getKey());
+ }
+ }
+ }
+ return true;
+ },
+ true /* create if not found */);
+ }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/ForegroundServicesUserState.java b/packages/SystemUI/src/com/android/systemui/ForegroundServicesUserState.java
new file mode 100644
index 0000000..a8ae654
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/ForegroundServicesUserState.java
@@ -0,0 +1,149 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui;
+
+import android.util.ArrayMap;
+import android.util.ArraySet;
+
+import java.util.Arrays;
+
+/**
+ * Struct to track relevant packages and notifications for a userid's foreground services.
+ */
+class ForegroundServicesUserState {
+ // shelf life of foreground services before they go bad
+ private static final long FG_SERVICE_GRACE_MILLIS = 5000;
+
+ private String[] mRunning = null;
+ private long mServiceStartTime = 0;
+ // package -> sufficiently important posted notification keys
+ private ArrayMap<String, ArraySet<String>> mImportantNotifications = new ArrayMap<>(1);
+ // package -> standard layout posted notification keys
+ private ArrayMap<String, ArraySet<String>> mStandardLayoutNotifications = new ArrayMap<>(1);
+
+ // package -> app ops
+ private ArrayMap<String, ArraySet<Integer>> mAppOps = new ArrayMap<>(1);
+
+ public void setRunningServices(String[] pkgs, long serviceStartTime) {
+ mRunning = pkgs != null ? Arrays.copyOf(pkgs, pkgs.length) : null;
+ mServiceStartTime = serviceStartTime;
+ }
+
+ public void addOp(String pkg, int op) {
+ if (mAppOps.get(pkg) == null) {
+ mAppOps.put(pkg, new ArraySet<>(3));
+ }
+ mAppOps.get(pkg).add(op);
+ }
+
+ public boolean removeOp(String pkg, int op) {
+ final boolean found;
+ final ArraySet<Integer> keys = mAppOps.get(pkg);
+ if (keys == null) {
+ found = false;
+ } else {
+ found = keys.remove(op);
+ if (keys.size() == 0) {
+ mAppOps.remove(pkg);
+ }
+ }
+ return found;
+ }
+
+ public void addImportantNotification(String pkg, String key) {
+ addNotification(mImportantNotifications, pkg, key);
+ }
+
+ public boolean removeImportantNotification(String pkg, String key) {
+ return removeNotification(mImportantNotifications, pkg, key);
+ }
+
+ public void addStandardLayoutNotification(String pkg, String key) {
+ addNotification(mStandardLayoutNotifications, pkg, key);
+ }
+
+ public boolean removeStandardLayoutNotification(String pkg, String key) {
+ return removeNotification(mStandardLayoutNotifications, pkg, key);
+ }
+
+ public boolean removeNotification(String pkg, String key) {
+ boolean removed = false;
+ removed |= removeImportantNotification(pkg, key);
+ removed |= removeStandardLayoutNotification(pkg, key);
+ return removed;
+ }
+
+ public void addNotification(ArrayMap<String, ArraySet<String>> map, String pkg,
+ String key) {
+ if (map.get(pkg) == null) {
+ map.put(pkg, new ArraySet<>());
+ }
+ map.get(pkg).add(key);
+ }
+
+ public boolean removeNotification(ArrayMap<String, ArraySet<String>> map,
+ String pkg, String key) {
+ final boolean found;
+ final ArraySet<String> keys = map.get(pkg);
+ if (keys == null) {
+ found = false;
+ } else {
+ found = keys.remove(key);
+ if (keys.size() == 0) {
+ map.remove(pkg);
+ }
+ }
+ return found;
+ }
+
+ public boolean isDisclosureNeeded() {
+ if (mRunning != null
+ && System.currentTimeMillis() - mServiceStartTime
+ >= FG_SERVICE_GRACE_MILLIS) {
+
+ for (String pkg : mRunning) {
+ final ArraySet<String> set = mImportantNotifications.get(pkg);
+ if (set == null || set.size() == 0) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ public ArraySet<Integer> getFeatures(String pkg) {
+ return mAppOps.get(pkg);
+ }
+
+ public String getStandardLayoutKey(String pkg) {
+ final ArraySet<String> set = mStandardLayoutNotifications.get(pkg);
+ if (set == null || set.size() == 0) {
+ return null;
+ }
+ return set.valueAt(0);
+ }
+
+ @Override
+ public String toString() {
+ return "UserServices{"
+ + "mRunning=" + Arrays.toString(mRunning)
+ + ", mServiceStartTime=" + mServiceStartTime
+ + ", mImportantNotifications=" + mImportantNotifications
+ + ", mStandardLayoutNotifications=" + mStandardLayoutNotifications
+ + '}';
+ }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/SystemUIFactory.java b/packages/SystemUI/src/com/android/systemui/SystemUIFactory.java
index e3bfdc9..5347a5c 100644
--- a/packages/SystemUI/src/com/android/systemui/SystemUIFactory.java
+++ b/packages/SystemUI/src/com/android/systemui/SystemUIFactory.java
@@ -16,6 +16,7 @@
package com.android.systemui;
+import static com.android.systemui.Dependency.ALLOW_NOTIFICATION_LONG_PRESS_NAME;
import static com.android.systemui.Dependency.LEAK_REPORT_EMAIL_NAME;
import android.annotation.Nullable;
@@ -50,6 +51,7 @@
import com.android.systemui.statusbar.phone.NotificationIconAreaController;
import com.android.systemui.statusbar.phone.ScrimController;
import com.android.systemui.statusbar.phone.ScrimState;
+import com.android.systemui.statusbar.phone.ShadeController;
import com.android.systemui.statusbar.phone.StatusBar;
import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager;
import com.android.systemui.statusbar.policy.DeviceProvisionedController;
@@ -200,6 +202,19 @@
return new NotificationInterruptionStateProvider(context);
}
+ @Singleton
+ @Provides
+ @Named(ALLOW_NOTIFICATION_LONG_PRESS_NAME)
+ public boolean provideAllowNotificationLongPress() {
+ return true;
+ }
+
+ @Singleton
+ @Provides
+ public ShadeController provideShadeController(Context context) {
+ return SysUiServiceProvider.getComponent(context, StatusBar.class);
+ }
+
@Module
protected static class ContextHolder {
private Context mContext;
diff --git a/packages/SystemUI/src/com/android/systemui/doze/DozeUi.java b/packages/SystemUI/src/com/android/systemui/doze/DozeUi.java
index 67aa82d..7656564 100644
--- a/packages/SystemUI/src/com/android/systemui/doze/DozeUi.java
+++ b/packages/SystemUI/src/com/android/systemui/doze/DozeUi.java
@@ -124,6 +124,7 @@
unscheduleTimeTick();
break;
case DOZE_REQUEST_PULSE:
+ scheduleTimeTick();
pulseWhileDozing(mMachine.getPulseReason());
break;
case INITIALIZED:
diff --git a/packages/SystemUI/src/com/android/systemui/qs/AutoAddTracker.java b/packages/SystemUI/src/com/android/systemui/qs/AutoAddTracker.java
index dfd3f73..2365e67 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/AutoAddTracker.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/AutoAddTracker.java
@@ -35,6 +35,8 @@
import java.util.Collection;
import java.util.Collections;
+import javax.inject.Inject;
+
public class AutoAddTracker {
private static final String[][] CONVERT_PREFS = {
@@ -48,6 +50,7 @@
private final ArraySet<String> mAutoAdded;
private final Context mContext;
+ @Inject
public AutoAddTracker(Context context) {
mContext = context;
mAutoAdded = new ArraySet<>(getAdded());
diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSTileHost.java b/packages/SystemUI/src/com/android/systemui/qs/QSTileHost.java
index 3a6b785..dfc3e66 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/QSTileHost.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/QSTileHost.java
@@ -56,6 +56,7 @@
import javax.inject.Inject;
import javax.inject.Named;
+import javax.inject.Provider;
import javax.inject.Singleton;
/** Platform implementation of the quick settings tile host **/
@@ -74,7 +75,7 @@
private final PluginManager mPluginManager;
private final List<Callback> mCallbacks = new ArrayList<>();
- private final AutoTileManager mAutoTiles;
+ private AutoTileManager mAutoTiles;
private final StatusBarIconController mIconController;
private final ArrayList<QSFactory> mQsFactories = new ArrayList<>();
private int mCurrentUser;
@@ -87,7 +88,8 @@
@Named(Dependency.MAIN_HANDLER_NAME) Handler mainHandler,
@Named(Dependency.BG_LOOPER_NAME) Looper bgLooper,
PluginManager pluginManager,
- TunerService tunerService) {
+ TunerService tunerService,
+ Provider<AutoTileManager> autoTiles) {
mIconController = iconController;
mContext = context;
mTunerService = tunerService;
@@ -104,9 +106,9 @@
// QSTileHost -> XXXTile -> QSTileHost. Posting ensures creation
// finishes before creating any tiles.
tunerService.addTunable(this, TILES_SETTING);
+ // AutoTileManager can modify mTiles so make sure mTiles has already been initialized.
+ mAutoTiles = autoTiles.get();
});
- // AutoTileManager can modify mTiles so make sure mTiles has already been initialized.
- mAutoTiles = new AutoTileManager(context, this);
}
public StatusBarIconController getIconController() {
@@ -264,7 +266,7 @@
@Override
public void unmarkTileAsAutoAdded(String spec) {
- mAutoTiles.unmarkTileAsAutoAdded(spec);
+ if (mAutoTiles != null) mAutoTiles.unmarkTileAsAutoAdded(spec);
}
public void addTile(String spec) {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationEntryManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationEntryManager.java
index 8afca1e..2d31650 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationEntryManager.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationEntryManager.java
@@ -21,7 +21,6 @@
import android.app.Notification;
import android.content.Context;
import android.os.Handler;
-import android.os.PowerManager;
import android.os.UserHandle;
import android.service.notification.NotificationListenerService;
import android.service.notification.StatusBarNotification;
@@ -41,7 +40,6 @@
import com.android.systemui.statusbar.NotificationUiAdjustment;
import com.android.systemui.statusbar.NotificationUpdateHandler;
import com.android.systemui.statusbar.notification.NotificationData.KeyguardEnvironment;
-import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
import com.android.systemui.statusbar.notification.row.NotificationGutsManager;
import com.android.systemui.statusbar.notification.row.NotificationInflater;
import com.android.systemui.statusbar.notification.row.NotificationInflater.InflationFlag;
@@ -92,9 +90,7 @@
private Runnable mUpdateNotificationViewsCallback;
private NotificationPresenter mPresenter;
- protected PowerManager mPowerManager;
private NotificationListenerService.RankingMap mLatestRankingMap;
- protected HeadsUpManager mHeadsUpManager;
protected NotificationData mNotificationData;
protected NotificationListContainer mListContainer;
@VisibleForTesting
@@ -130,7 +126,6 @@
public NotificationEntryManager(Context context) {
mContext = context;
- mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
mBubbleController.setDismissListener(this /* bubbleEventListener */);
mNotificationData = new NotificationData();
mDeferredNotificationViewUpdateHandler = new Handler();
@@ -163,8 +158,7 @@
HeadsUpManager headsUpManager) {
mPresenter = presenter;
mUpdateNotificationViewsCallback = mPresenter::updateNotificationViews;
- mHeadsUpManager = headsUpManager;
- mNotificationData.setHeadsUpManager(mHeadsUpManager);
+ mNotificationData.setHeadsUpManager(headsUpManager);
mListContainer = listContainer;
mDeviceProvisionedController.addCallback(mDeviceProvisionedListener);
@@ -195,10 +189,6 @@
return mPresenter;
}
- public ExpandableNotificationRow.LongPressListener getNotificationLongClicker() {
- return getRowBinder().getNotificationLongClicker();
- }
-
@Override
public void onReorderingAllowed() {
updateNotifications();
@@ -344,8 +334,6 @@
extender.setShouldManageLifetime(entry, false /* shouldManage */);
}
- mForegroundServiceController.removeNotification(entry.notification);
-
if (entry.rowExists()) {
entry.removeRow();
mListContainer.cleanUpViewStateForEntry(entry);
@@ -462,9 +450,6 @@
NotificationData.Entry entry = createNotificationEntry(notification, ranking);
abortExistingInflation(key);
- mForegroundServiceController.addNotification(notification,
- mNotificationData.getImportance(key));
-
mPendingNotifications.put(key, entry);
for (NotificationEntryListener listener : mNotificationEntryListeners) {
listener.onPendingEntryAdded(entry);
@@ -525,9 +510,6 @@
getRowBinder().inflateViews(entry, () -> performRemoveNotification(notification),
mNotificationData.get(entry.key) != null);
- mForegroundServiceController.updateNotification(notification,
- mNotificationData.getImportance(key));
-
updateNotifications();
if (!notification.isClearable()) {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationFilter.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationFilter.java
index 5e99c38..700382a 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationFilter.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationFilter.java
@@ -117,8 +117,8 @@
return true;
}
- if (getFsc().isDungeonNotification(sbn)
- && !getFsc().isDungeonNeededForUser(sbn.getUserId())) {
+ if (getFsc().isDisclosureNotification(sbn)
+ && !getFsc().isDisclosureNeededForUser(sbn.getUserId())) {
// this is a foreground-service disclosure for a user that does not need to show one
return true;
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationRowBinder.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationRowBinder.java
index 20a1e13..058efca 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationRowBinder.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationRowBinder.java
@@ -17,6 +17,7 @@
package com.android.systemui.statusbar.notification;
import static com.android.internal.util.Preconditions.checkNotNull;
+import static com.android.systemui.Dependency.ALLOW_NOTIFICATION_LONG_PRESS_NAME;
import static com.android.systemui.statusbar.NotificationRemoteInputManager.ENABLE_REMOTE_INPUT;
import static com.android.systemui.statusbar.notification.row.NotificationInflater.FLAG_CONTENT_VIEW_AMBIENT;
import static com.android.systemui.statusbar.notification.row.NotificationInflater.FLAG_CONTENT_VIEW_HEADS_UP;
@@ -51,6 +52,7 @@
import com.android.systemui.statusbar.policy.HeadsUpManager;
import javax.inject.Inject;
+import javax.inject.Named;
import javax.inject.Singleton;
/** Handles inflating and updating views for notifications. */
@@ -72,6 +74,7 @@
private final NotificationMessagingUtil mMessagingUtil;
private final ExpandableNotificationRow.ExpansionLogger mExpansionLogger =
this::logNotificationExpansion;
+ private final boolean mAllowLongPress;
private NotificationRemoteInputManager mRemoteInputManager;
private NotificationPresenter mPresenter;
@@ -83,9 +86,11 @@
private NotificationClicker mNotificationClicker;
@Inject
- public NotificationRowBinder(Context context) {
+ public NotificationRowBinder(Context context,
+ @Named(ALLOW_NOTIFICATION_LONG_PRESS_NAME) boolean allowLongPress) {
mContext = context;
mMessagingUtil = new NotificationMessagingUtil(context);
+ mAllowLongPress = allowLongPress;
mBarService = IStatusBarService.Stub.asInterface(
ServiceManager.getService(Context.STATUS_BAR_SERVICE));
}
@@ -152,7 +157,9 @@
row.setHeadsUpManager(mHeadsUpManager);
row.setOnExpandClickListener(mPresenter);
row.setInflationCallback(mInflationCallback);
- row.setLongPressListener(getNotificationLongClicker());
+ if (mAllowLongPress) {
+ row.setLongPressListener(mGutsManager::openGuts);
+ }
mListContainer.bindRow(row);
getRemoteInputManager().bindRow(row);
@@ -265,10 +272,6 @@
row.inflateViews();
}
- ExpandableNotificationRow.LongPressListener getNotificationLongClicker() {
- return mGutsManager::openGuts;
- }
-
private void logNotificationExpansion(String key, boolean userAction, boolean expanded) {
mUiOffloadThread.submit(() -> {
try {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java
index f982ecf..8deb7d5 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java
@@ -16,9 +16,11 @@
package com.android.systemui.statusbar.notification.stack;
+import static com.android.systemui.Dependency.ALLOW_NOTIFICATION_LONG_PRESS_NAME;
import static com.android.systemui.statusbar.notification.ActivityLaunchAnimator.ExpandAnimationParameters;
import static com.android.systemui.statusbar.notification.stack.StackStateAnimator.ANIMATION_DURATION_SWIPE;
import static com.android.systemui.statusbar.phone.NotificationIconAreaController.LOW_PRIORITY;
+import static com.android.systemui.util.InjectionInflationController.VIEW_CONTEXT;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
@@ -136,6 +138,9 @@
import java.util.List;
import java.util.function.BiConsumer;
+import javax.inject.Inject;
+import javax.inject.Named;
+
/**
* A layout which handles a dynamic amount of notifications and presents them in a scrollable stack.
*/
@@ -165,6 +170,7 @@
private final Paint mBackgroundPaint = new Paint();
private final boolean mShouldDrawNotificationBackground;
private boolean mLowPriorityBeforeSpeedBump;
+ private final boolean mAllowLongPress;
private float mExpandedHeight;
private int mOwnScrollY;
@@ -452,27 +458,16 @@
private final NotificationGutsManager
mNotificationGutsManager = Dependency.get(NotificationGutsManager.class);
- @ShadeViewRefactor(RefactorComponent.SHADE_VIEW)
- public NotificationStackScrollLayout(Context context) {
- this(context, null);
- }
-
- @ShadeViewRefactor(RefactorComponent.SHADE_VIEW)
- public NotificationStackScrollLayout(Context context, AttributeSet attrs) {
- this(context, attrs, 0);
- }
-
- @ShadeViewRefactor(RefactorComponent.SHADE_VIEW)
- public NotificationStackScrollLayout(Context context, AttributeSet attrs, int defStyleAttr) {
- this(context, attrs, defStyleAttr, 0);
- }
-
- @ShadeViewRefactor(RefactorComponent.SHADE_VIEW)
- public NotificationStackScrollLayout(Context context, AttributeSet attrs, int defStyleAttr,
- int defStyleRes) {
- super(context, attrs, defStyleAttr, defStyleRes);
+ @Inject
+ public NotificationStackScrollLayout(
+ @Named(VIEW_CONTEXT) Context context,
+ AttributeSet attrs,
+ @Named(ALLOW_NOTIFICATION_LONG_PRESS_NAME) boolean allowLongPress) {
+ super(context, attrs, 0, 0);
Resources res = getResources();
+ mAllowLongPress = allowLongPress;
+
for (int i = 0; i < NUM_SECTIONS; i++) {
mSections[i] = new NotificationSection(this);
}
@@ -532,7 +527,9 @@
inflateEmptyShadeView();
inflateFooterView();
mVisualStabilityManager.setVisibilityLocationProvider(this::isInVisibleLocation);
- setLongPressListener(mEntryManager.getNotificationLongClicker());
+ if (mAllowLongPress) {
+ setLongPressListener(mGutsManager::openGuts);
+ }
}
@Override
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationSwipeHelper.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationSwipeHelper.java
index f1d9549..975aee5 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationSwipeHelper.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationSwipeHelper.java
@@ -189,10 +189,13 @@
boolean isFastNonDismissGesture =
gestureFastEnough && !gestureTowardsMenu && !isDismissGesture;
boolean isMenuRevealingGestureAwayFromMenu = slowSwipedFarEnough || isFastNonDismissGesture;
- if (isNonDismissGestureTowardsMenu
- || (!isFalseGesture(ev) && isMenuRevealingGestureAwayFromMenu)) {
+ int menuSnapTarget = menuRow.getMenuSnapTarget();
+ boolean isNonFalseMenuRevealingGesture =
+ !isFalseGesture(ev) && isMenuRevealingGestureAwayFromMenu;
+ if ((isNonDismissGestureTowardsMenu || isNonFalseMenuRevealingGesture)
+ && menuSnapTarget != 0) {
// Menu has not been snapped to previously and this is menu revealing gesture
- snapOpen(animView, menuRow.getMenuSnapTarget(), velocity);
+ snapOpen(animView, menuSnapTarget, velocity);
menuRow.onSnapOpen();
} else if (isDismissGesture(ev) && !gestureTowardsMenu) {
dismiss(animView, velocity);
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/AutoTileManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/AutoTileManager.java
index 1d7e899..fac4dbb 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/AutoTileManager.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/AutoTileManager.java
@@ -30,6 +30,9 @@
import com.android.systemui.statusbar.policy.HotspotController;
import com.android.systemui.statusbar.policy.HotspotController.Callback;
+import javax.inject.Inject;
+import javax.inject.Named;
+
/**
* Manages which tiles should be automatically added to QS.
*/
@@ -44,24 +47,31 @@
private final QSTileHost mHost;
private final Handler mHandler;
private final AutoAddTracker mAutoTracker;
+ private final HotspotController mHotspotController;
+ private final DataSaverController mDataSaverController;
+ private final ManagedProfileController mManagedProfileController;
+ private final ColorDisplayController mColorDisplayController;
- public AutoTileManager(Context context, QSTileHost host) {
- this(context, new AutoAddTracker(context), host,
- new Handler(Dependency.get(Dependency.BG_LOOPER)));
- }
-
- @VisibleForTesting
- AutoTileManager(Context context, AutoAddTracker autoAddTracker, QSTileHost host,
- Handler handler) {
+ @Inject
+ public AutoTileManager(Context context, AutoAddTracker autoAddTracker, QSTileHost host,
+ @Named(Dependency.BG_HANDLER_NAME) Handler handler,
+ HotspotController hotspotController,
+ DataSaverController dataSaverController,
+ ManagedProfileController managedProfileController,
+ ColorDisplayController colorDisplayController) {
mAutoTracker = autoAddTracker;
mContext = context;
mHost = host;
mHandler = handler;
+ mHotspotController = hotspotController;
+ mDataSaverController = dataSaverController;
+ mManagedProfileController = managedProfileController;
+ mColorDisplayController = colorDisplayController;
if (!mAutoTracker.isAdded(HOTSPOT)) {
- Dependency.get(HotspotController.class).addCallback(mHotspotCallback);
+ hotspotController.addCallback(mHotspotCallback);
}
if (!mAutoTracker.isAdded(SAVER)) {
- Dependency.get(DataSaverController.class).addCallback(mDataSaverListener);
+ dataSaverController.addCallback(mDataSaverListener);
}
if (!mAutoTracker.isAdded(INVERSION)) {
mColorsSetting = new SecureSetting(mContext, mHandler,
@@ -79,11 +89,11 @@
mColorsSetting.setListening(true);
}
if (!mAutoTracker.isAdded(WORK)) {
- Dependency.get(ManagedProfileController.class).addCallback(mProfileCallback);
+ managedProfileController.addCallback(mProfileCallback);
}
if (!mAutoTracker.isAdded(NIGHT)
&& ColorDisplayManager.isNightDisplayAvailable(mContext)) {
- Dependency.get(ColorDisplayController.class).setListener(mColorDisplayCallback);
+ colorDisplayController.setListener(mColorDisplayCallback);
}
}
@@ -92,11 +102,11 @@
mColorsSetting.setListening(false);
}
mAutoTracker.destroy();
- Dependency.get(HotspotController.class).removeCallback(mHotspotCallback);
- Dependency.get(DataSaverController.class).removeCallback(mDataSaverListener);
- Dependency.get(ManagedProfileController.class).removeCallback(mProfileCallback);
+ mHotspotController.removeCallback(mHotspotCallback);
+ mDataSaverController.removeCallback(mDataSaverListener);
+ mManagedProfileController.removeCallback(mProfileCallback);
if (ColorDisplayManager.isNightDisplayAvailable(mContext)) {
- Dependency.get(ColorDisplayController.class).setListener(null);
+ mColorDisplayController.setListener(null);
}
}
@@ -109,7 +119,7 @@
@Override
public void onManagedProfileChanged() {
if (mAutoTracker.isAdded(WORK)) return;
- if (Dependency.get(ManagedProfileController.class).hasActiveProfile()) {
+ if (mManagedProfileController.hasActiveProfile()) {
mHost.addTile(WORK);
mAutoTracker.setTileAdded(WORK);
}
@@ -129,8 +139,7 @@
if (isDataSaving) {
mHost.addTile(SAVER);
mAutoTracker.setTileAdded(SAVER);
- mHandler.post(() -> Dependency.get(DataSaverController.class).removeCallback(
- mDataSaverListener));
+ mHandler.post(() -> mDataSaverController.removeCallback(mDataSaverListener));
}
}
};
@@ -142,8 +151,7 @@
if (enabled) {
mHost.addTile(HOTSPOT);
mAutoTracker.setTileAdded(HOTSPOT);
- mHandler.post(() -> Dependency.get(HotspotController.class)
- .removeCallback(mHotspotCallback));
+ mHandler.post(() -> mHotspotController.removeCallback(mHotspotCallback));
}
}
};
@@ -170,8 +178,7 @@
if (mAutoTracker.isAdded(NIGHT)) return;
mHost.addTile(NIGHT);
mAutoTracker.setTileAdded(NIGHT);
- mHandler.post(() -> Dependency.get(ColorDisplayController.class)
- .setListener(null));
+ mHandler.post(() -> mColorDisplayController.setListener(null));
}
};
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationPresenter.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationPresenter.java
index 7b7bcb4..b9372e8 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationPresenter.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationPresenter.java
@@ -43,6 +43,7 @@
import com.android.internal.widget.MessagingMessage;
import com.android.keyguard.KeyguardUpdateMonitor;
import com.android.systemui.Dependency;
+import com.android.systemui.ForegroundServiceNotificationListener;
import com.android.systemui.InitController;
import com.android.systemui.R;
import com.android.systemui.plugins.ActivityStarter;
@@ -228,6 +229,10 @@
mVisualStabilityManager.setUpWithPresenter(this);
gutsManager.setUpWithPresenter(this,
notifListContainer, mCheckSaveListener, mOnSettingsClickListener);
+ // ForegroundServiceControllerListener adds its listener in its constructor
+ // but we need to request it here in order for it to be instantiated.
+ // TODO: figure out how to do this correctly once Dependency.get() is gone.
+ Dependency.get(ForegroundServiceNotificationListener.class);
onUserSwitched(mLockscreenUserManager.getCurrentUserId());
});
diff --git a/packages/SystemUI/src/com/android/systemui/util/InjectionInflationController.java b/packages/SystemUI/src/com/android/systemui/util/InjectionInflationController.java
index 59aa522..faebf60 100644
--- a/packages/SystemUI/src/com/android/systemui/util/InjectionInflationController.java
+++ b/packages/SystemUI/src/com/android/systemui/util/InjectionInflationController.java
@@ -26,6 +26,7 @@
import com.android.systemui.SystemUIFactory;
import com.android.systemui.qs.QSFooterImpl;
import com.android.systemui.qs.QuickStatusBarHeader;
+import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@@ -112,6 +113,11 @@
* Creates the QSFooterImpl.
*/
QSFooterImpl createQsFooter();
+
+ /**
+ * Creates the NotificationStackScrollLayout.
+ */
+ NotificationStackScrollLayout createNotificationStackScrollLayout();
}
/**
diff --git a/packages/SystemUI/tests/src/com/android/systemui/ForegroundServiceControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/ForegroundServiceControllerTest.java
index f278a17..199a3a6 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/ForegroundServiceControllerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/ForegroundServiceControllerTest.java
@@ -22,6 +22,7 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.annotation.UserIdInt;
@@ -35,197 +36,95 @@
import android.widget.RemoteViews;
import com.android.internal.messages.nano.SystemMessageProto;
+import com.android.systemui.statusbar.notification.NotificationData;
+import com.android.systemui.statusbar.notification.NotificationEntryListener;
+import com.android.systemui.statusbar.notification.NotificationEntryManager;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
@SmallTest
@RunWith(AndroidJUnit4.class)
public class ForegroundServiceControllerTest extends SysuiTestCase {
- public static @UserIdInt int USERID_ONE = 10; // UserManagerService.MIN_USER_ID;
- public static @UserIdInt int USERID_TWO = USERID_ONE + 1;
+ @UserIdInt private static final int USERID_ONE = 10; // UserManagerService.MIN_USER_ID;
+ @UserIdInt private static final int USERID_TWO = USERID_ONE + 1;
- private ForegroundServiceController fsc;
+ private ForegroundServiceController mFsc;
+ private ForegroundServiceNotificationListener mListener;
+ private NotificationEntryListener mEntryListener;
@Before
public void setUp() throws Exception {
- fsc = new ForegroundServiceControllerImpl(mContext);
- }
-
- @Test
- public void testNotificationCRUD_dungeon() {
- StatusBarNotification sbn_user1_app1_fg = makeMockFgSBN(USERID_ONE, "com.example.app1");
- StatusBarNotification sbn_user2_app2_fg = makeMockFgSBN(USERID_TWO, "com.example.app2");
- StatusBarNotification sbn_user1_app3_fg = makeMockFgSBN(USERID_ONE, "com.example.app3");
- StatusBarNotification sbn_user1_app1 = makeMockSBN(USERID_ONE, "com.example.app1",
- 5000, "monkeys", Notification.FLAG_AUTO_CANCEL);
- StatusBarNotification sbn_user2_app1 = makeMockSBN(USERID_TWO, "com.example.app1",
- 5000, "monkeys", Notification.FLAG_AUTO_CANCEL);
-
- assertFalse(fsc.removeNotification(sbn_user1_app3_fg));
- assertFalse(fsc.removeNotification(sbn_user2_app2_fg));
- assertFalse(fsc.removeNotification(sbn_user1_app1_fg));
- assertFalse(fsc.removeNotification(sbn_user1_app1));
- assertFalse(fsc.removeNotification(sbn_user2_app1));
-
- fsc.addNotification(sbn_user1_app1_fg, NotificationManager.IMPORTANCE_DEFAULT);
- fsc.addNotification(sbn_user2_app2_fg, NotificationManager.IMPORTANCE_DEFAULT);
- fsc.addNotification(sbn_user1_app3_fg, NotificationManager.IMPORTANCE_DEFAULT);
- fsc.addNotification(sbn_user1_app1, NotificationManager.IMPORTANCE_DEFAULT);
- fsc.addNotification(sbn_user2_app1, NotificationManager.IMPORTANCE_DEFAULT);
-
- // these are never added to the tracker
- assertFalse(fsc.removeNotification(sbn_user1_app1));
- assertFalse(fsc.removeNotification(sbn_user2_app1));
-
- fsc.updateNotification(sbn_user1_app1, NotificationManager.IMPORTANCE_DEFAULT);
- fsc.updateNotification(sbn_user2_app1, NotificationManager.IMPORTANCE_DEFAULT);
- // should still not be there
- assertFalse(fsc.removeNotification(sbn_user1_app1));
- assertFalse(fsc.removeNotification(sbn_user2_app1));
-
- fsc.updateNotification(sbn_user2_app2_fg, NotificationManager.IMPORTANCE_DEFAULT);
- fsc.updateNotification(sbn_user1_app3_fg, NotificationManager.IMPORTANCE_DEFAULT);
- fsc.updateNotification(sbn_user1_app1_fg, NotificationManager.IMPORTANCE_DEFAULT);
-
- assertTrue(fsc.removeNotification(sbn_user1_app3_fg));
- assertFalse(fsc.removeNotification(sbn_user1_app3_fg));
-
- assertTrue(fsc.removeNotification(sbn_user2_app2_fg));
- assertFalse(fsc.removeNotification(sbn_user2_app2_fg));
-
- assertTrue(fsc.removeNotification(sbn_user1_app1_fg));
- assertFalse(fsc.removeNotification(sbn_user1_app1_fg));
-
- assertFalse(fsc.removeNotification(sbn_user1_app1));
- assertFalse(fsc.removeNotification(sbn_user2_app1));
- }
-
- @Test
- public void testNotificationCRUD_stdLayout() {
- StatusBarNotification sbn_user1_app1_fg =
- makeMockFgSBN(USERID_ONE, "com.example.app1", 0, true);
- StatusBarNotification sbn_user2_app2_fg =
- makeMockFgSBN(USERID_TWO, "com.example.app2", 1, true);
- StatusBarNotification sbn_user1_app3_fg =
- makeMockFgSBN(USERID_ONE, "com.example.app3", 2, true);
- StatusBarNotification sbn_user1_app1 = makeMockSBN(USERID_ONE, "com.example.app1",
- 5000, "monkeys", Notification.FLAG_AUTO_CANCEL);
- StatusBarNotification sbn_user2_app1 = makeMockSBN(USERID_TWO, "com.example.app1",
- 5000, "monkeys", Notification.FLAG_AUTO_CANCEL);
-
- assertFalse(fsc.removeNotification(sbn_user1_app3_fg));
- assertFalse(fsc.removeNotification(sbn_user2_app2_fg));
- assertFalse(fsc.removeNotification(sbn_user1_app1_fg));
- assertFalse(fsc.removeNotification(sbn_user1_app1));
- assertFalse(fsc.removeNotification(sbn_user2_app1));
-
- fsc.addNotification(sbn_user1_app1_fg, NotificationManager.IMPORTANCE_MIN);
- fsc.addNotification(sbn_user2_app2_fg, NotificationManager.IMPORTANCE_MIN);
- fsc.addNotification(sbn_user1_app3_fg, NotificationManager.IMPORTANCE_MIN);
- fsc.addNotification(sbn_user1_app1, NotificationManager.IMPORTANCE_MIN);
- fsc.addNotification(sbn_user2_app1, NotificationManager.IMPORTANCE_MIN);
-
- // these are never added to the tracker
- assertFalse(fsc.removeNotification(sbn_user1_app1));
- assertFalse(fsc.removeNotification(sbn_user2_app1));
-
- fsc.updateNotification(sbn_user1_app1, NotificationManager.IMPORTANCE_MIN);
- fsc.updateNotification(sbn_user2_app1, NotificationManager.IMPORTANCE_MIN);
- // should still not be there
- assertFalse(fsc.removeNotification(sbn_user1_app1));
- assertFalse(fsc.removeNotification(sbn_user2_app1));
-
- fsc.updateNotification(sbn_user2_app2_fg, NotificationManager.IMPORTANCE_MIN);
- fsc.updateNotification(sbn_user1_app3_fg, NotificationManager.IMPORTANCE_MIN);
- fsc.updateNotification(sbn_user1_app1_fg, NotificationManager.IMPORTANCE_MIN);
-
- assertTrue(fsc.removeNotification(sbn_user1_app3_fg));
- assertFalse(fsc.removeNotification(sbn_user1_app3_fg));
-
- assertTrue(fsc.removeNotification(sbn_user2_app2_fg));
- assertFalse(fsc.removeNotification(sbn_user2_app2_fg));
-
- assertTrue(fsc.removeNotification(sbn_user1_app1_fg));
- assertFalse(fsc.removeNotification(sbn_user1_app1_fg));
-
- assertFalse(fsc.removeNotification(sbn_user1_app1));
- assertFalse(fsc.removeNotification(sbn_user2_app1));
+ mFsc = new ForegroundServiceController();
+ NotificationEntryManager notificationEntryManager = mock(NotificationEntryManager.class);
+ mListener = new ForegroundServiceNotificationListener(
+ mContext, mFsc, notificationEntryManager);
+ ArgumentCaptor<NotificationEntryListener> entryListenerCaptor =
+ ArgumentCaptor.forClass(NotificationEntryListener.class);
+ verify(notificationEntryManager).addNotificationEntryListener(
+ entryListenerCaptor.capture());
+ mEntryListener = entryListenerCaptor.getValue();
}
@Test
public void testAppOpsCRUD() {
// no crash on remove that doesn't exist
- fsc.onAppOpChanged(9, 1000, "pkg1", false);
- assertNull(fsc.getAppOps(0, "pkg1"));
+ mFsc.onAppOpChanged(9, 1000, "pkg1", false);
+ assertNull(mFsc.getAppOps(0, "pkg1"));
// multiuser & multipackage
- fsc.onAppOpChanged(8, 50, "pkg1", true);
- fsc.onAppOpChanged(1, 60, "pkg3", true);
- fsc.onAppOpChanged(7, 500000, "pkg2", true);
+ mFsc.onAppOpChanged(8, 50, "pkg1", true);
+ mFsc.onAppOpChanged(1, 60, "pkg3", true);
+ mFsc.onAppOpChanged(7, 500000, "pkg2", true);
- assertEquals(1, fsc.getAppOps(0, "pkg1").size());
- assertTrue(fsc.getAppOps(0, "pkg1").contains(8));
+ assertEquals(1, mFsc.getAppOps(0, "pkg1").size());
+ assertTrue(mFsc.getAppOps(0, "pkg1").contains(8));
- assertEquals(1, fsc.getAppOps(UserHandle.getUserId(500000), "pkg2").size());
- assertTrue(fsc.getAppOps(UserHandle.getUserId(500000), "pkg2").contains(7));
+ assertEquals(1, mFsc.getAppOps(UserHandle.getUserId(500000), "pkg2").size());
+ assertTrue(mFsc.getAppOps(UserHandle.getUserId(500000), "pkg2").contains(7));
- assertEquals(1, fsc.getAppOps(0, "pkg3").size());
- assertTrue(fsc.getAppOps(0, "pkg3").contains(1));
+ assertEquals(1, mFsc.getAppOps(0, "pkg3").size());
+ assertTrue(mFsc.getAppOps(0, "pkg3").contains(1));
// multiple ops for the same package
- fsc.onAppOpChanged(9, 50, "pkg1", true);
- fsc.onAppOpChanged(5, 50, "pkg1", true);
+ mFsc.onAppOpChanged(9, 50, "pkg1", true);
+ mFsc.onAppOpChanged(5, 50, "pkg1", true);
- assertEquals(3, fsc.getAppOps(0, "pkg1").size());
- assertTrue(fsc.getAppOps(0, "pkg1").contains(8));
- assertTrue(fsc.getAppOps(0, "pkg1").contains(9));
- assertTrue(fsc.getAppOps(0, "pkg1").contains(5));
+ assertEquals(3, mFsc.getAppOps(0, "pkg1").size());
+ assertTrue(mFsc.getAppOps(0, "pkg1").contains(8));
+ assertTrue(mFsc.getAppOps(0, "pkg1").contains(9));
+ assertTrue(mFsc.getAppOps(0, "pkg1").contains(5));
- assertEquals(1, fsc.getAppOps(UserHandle.getUserId(500000), "pkg2").size());
- assertTrue(fsc.getAppOps(UserHandle.getUserId(500000), "pkg2").contains(7));
+ assertEquals(1, mFsc.getAppOps(UserHandle.getUserId(500000), "pkg2").size());
+ assertTrue(mFsc.getAppOps(UserHandle.getUserId(500000), "pkg2").contains(7));
// remove one of the multiples
- fsc.onAppOpChanged(9, 50, "pkg1", false);
- assertEquals(2, fsc.getAppOps(0, "pkg1").size());
- assertTrue(fsc.getAppOps(0, "pkg1").contains(8));
- assertTrue(fsc.getAppOps(0, "pkg1").contains(5));
+ mFsc.onAppOpChanged(9, 50, "pkg1", false);
+ assertEquals(2, mFsc.getAppOps(0, "pkg1").size());
+ assertTrue(mFsc.getAppOps(0, "pkg1").contains(8));
+ assertTrue(mFsc.getAppOps(0, "pkg1").contains(5));
// remove last op
- fsc.onAppOpChanged(1, 60, "pkg3", false);
- assertNull(fsc.getAppOps(0, "pkg3"));
+ mFsc.onAppOpChanged(1, 60, "pkg3", false);
+ assertNull(mFsc.getAppOps(0, "pkg3"));
}
@Test
- public void testDungeonPredicate() {
+ public void testDisclosurePredicate() {
StatusBarNotification sbn_user1_app1 = makeMockSBN(USERID_ONE, "com.example.app1",
5000, "monkeys", Notification.FLAG_AUTO_CANCEL);
- StatusBarNotification sbn_user1_dungeon = makeMockSBN(USERID_ONE, "android",
+ StatusBarNotification sbn_user1_disclosure = makeMockSBN(USERID_ONE, "android",
SystemMessageProto.SystemMessage.NOTE_FOREGROUND_SERVICES,
null, Notification.FLAG_NO_CLEAR);
- assertTrue(fsc.isDungeonNotification(sbn_user1_dungeon));
- assertFalse(fsc.isDungeonNotification(sbn_user1_app1));
+ assertTrue(mFsc.isDisclosureNotification(sbn_user1_disclosure));
+ assertFalse(mFsc.isDisclosureNotification(sbn_user1_app1));
}
@Test
- public void testDungeonCRUD() {
- StatusBarNotification sbn_user1_app1 = makeMockSBN(USERID_ONE, "com.example.app1",
- 5000, "monkeys", Notification.FLAG_AUTO_CANCEL);
- StatusBarNotification sbn_user1_dungeon = makeMockSBN(USERID_ONE, "android",
- SystemMessageProto.SystemMessage.NOTE_FOREGROUND_SERVICES,
- null, Notification.FLAG_NO_CLEAR);
-
- fsc.addNotification(sbn_user1_app1, NotificationManager.IMPORTANCE_DEFAULT);
- fsc.addNotification(sbn_user1_dungeon, NotificationManager.IMPORTANCE_DEFAULT);
-
- fsc.removeNotification(sbn_user1_dungeon);
- assertFalse(fsc.removeNotification(sbn_user1_app1));
- }
-
- @Test
- public void testNeedsDungeonAfterRemovingUnrelatedNotification() {
+ public void testNeedsDisclosureAfterRemovingUnrelatedNotification() {
final String PKG1 = "com.example.app100";
StatusBarNotification sbn_user1_app1 = makeMockSBN(USERID_ONE, PKG1,
@@ -233,21 +132,21 @@
StatusBarNotification sbn_user1_app1_fg = makeMockFgSBN(USERID_ONE, PKG1);
// first add a normal notification
- fsc.addNotification(sbn_user1_app1, NotificationManager.IMPORTANCE_DEFAULT);
+ entryAdded(sbn_user1_app1, NotificationManager.IMPORTANCE_DEFAULT);
// nothing required yet
- assertFalse(fsc.isDungeonNeededForUser(USERID_ONE));
+ assertFalse(mFsc.isDisclosureNeededForUser(USERID_ONE));
// now the app starts a fg service
- fsc.addNotification(makeMockDungeon(USERID_ONE, new String[]{ PKG1 }),
+ entryAdded(makeMockDisclosure(USERID_ONE, new String[]{PKG1}),
NotificationManager.IMPORTANCE_DEFAULT);
- assertTrue(fsc.isDungeonNeededForUser(USERID_ONE)); // should be required!
+ assertTrue(mFsc.isDisclosureNeededForUser(USERID_ONE)); // should be required!
// add the fg notification
- fsc.addNotification(sbn_user1_app1_fg, NotificationManager.IMPORTANCE_DEFAULT);
- assertFalse(fsc.isDungeonNeededForUser(USERID_ONE)); // app1 has got it covered
+ entryAdded(sbn_user1_app1_fg, NotificationManager.IMPORTANCE_DEFAULT);
+ assertFalse(mFsc.isDisclosureNeededForUser(USERID_ONE)); // app1 has got it covered
// remove the boring notification
- fsc.removeNotification(sbn_user1_app1);
- assertFalse(fsc.isDungeonNeededForUser(USERID_ONE)); // app1 has STILL got it covered
- assertTrue(fsc.removeNotification(sbn_user1_app1_fg));
- assertTrue(fsc.isDungeonNeededForUser(USERID_ONE)); // should be required!
+ entryRemoved(sbn_user1_app1);
+ assertFalse(mFsc.isDisclosureNeededForUser(USERID_ONE)); // app1 has STILL got it covered
+ entryRemoved(sbn_user1_app1_fg);
+ assertTrue(mFsc.isDisclosureNeededForUser(USERID_ONE)); // should be required!
}
@Test
@@ -257,115 +156,117 @@
StatusBarNotification sbn_user1_app1 = makeMockSBN(USERID_ONE, PKG1,
5000, "monkeys", Notification.FLAG_AUTO_CANCEL);
- fsc.addNotification(sbn_user1_app1, NotificationManager.IMPORTANCE_DEFAULT);
+ entryAdded(sbn_user1_app1, NotificationManager.IMPORTANCE_DEFAULT);
// no services are "running"
- fsc.addNotification(makeMockDungeon(USERID_ONE, null),
+ entryAdded(makeMockDisclosure(USERID_ONE, null),
NotificationManager.IMPORTANCE_DEFAULT);
- assertFalse(fsc.isDungeonNeededForUser(USERID_ONE));
- assertFalse(fsc.isDungeonNeededForUser(USERID_TWO));
+ assertFalse(mFsc.isDisclosureNeededForUser(USERID_ONE));
+ assertFalse(mFsc.isDisclosureNeededForUser(USERID_TWO));
- fsc.updateNotification(makeMockDungeon(USERID_ONE, new String[]{PKG1}),
+ entryUpdated(makeMockDisclosure(USERID_ONE, new String[]{PKG1}),
NotificationManager.IMPORTANCE_DEFAULT);
- assertTrue(fsc.isDungeonNeededForUser(USERID_ONE)); // should be required!
- assertFalse(fsc.isDungeonNeededForUser(USERID_TWO));
+ assertTrue(mFsc.isDisclosureNeededForUser(USERID_ONE)); // should be required!
+ assertFalse(mFsc.isDisclosureNeededForUser(USERID_TWO));
// switch to different package
- fsc.updateNotification(makeMockDungeon(USERID_ONE, new String[]{PKG2}),
+ entryUpdated(makeMockDisclosure(USERID_ONE, new String[]{PKG2}),
NotificationManager.IMPORTANCE_DEFAULT);
- assertTrue(fsc.isDungeonNeededForUser(USERID_ONE));
- assertFalse(fsc.isDungeonNeededForUser(USERID_TWO));
+ assertTrue(mFsc.isDisclosureNeededForUser(USERID_ONE));
+ assertFalse(mFsc.isDisclosureNeededForUser(USERID_TWO));
- fsc.updateNotification(makeMockDungeon(USERID_TWO, new String[]{PKG1}),
+ entryUpdated(makeMockDisclosure(USERID_TWO, new String[]{PKG1}),
NotificationManager.IMPORTANCE_DEFAULT);
- assertTrue(fsc.isDungeonNeededForUser(USERID_ONE));
- assertTrue(fsc.isDungeonNeededForUser(USERID_TWO)); // finally user2 needs one too
+ assertTrue(mFsc.isDisclosureNeededForUser(USERID_ONE));
+ assertTrue(mFsc.isDisclosureNeededForUser(USERID_TWO)); // finally user2 needs one too
- fsc.updateNotification(makeMockDungeon(USERID_ONE, new String[]{PKG2, PKG1}),
+ entryUpdated(makeMockDisclosure(USERID_ONE, new String[]{PKG2, PKG1}),
NotificationManager.IMPORTANCE_DEFAULT);
- assertTrue(fsc.isDungeonNeededForUser(USERID_ONE));
- assertTrue(fsc.isDungeonNeededForUser(USERID_TWO));
+ assertTrue(mFsc.isDisclosureNeededForUser(USERID_ONE));
+ assertTrue(mFsc.isDisclosureNeededForUser(USERID_TWO));
- fsc.removeNotification(makeMockDungeon(USERID_ONE, null /*unused*/));
- assertFalse(fsc.isDungeonNeededForUser(USERID_ONE));
- assertTrue(fsc.isDungeonNeededForUser(USERID_TWO));
+ entryRemoved(makeMockDisclosure(USERID_ONE, null /*unused*/));
+ assertFalse(mFsc.isDisclosureNeededForUser(USERID_ONE));
+ assertTrue(mFsc.isDisclosureNeededForUser(USERID_TWO));
- fsc.removeNotification(makeMockDungeon(USERID_TWO, null /*unused*/));
- assertFalse(fsc.isDungeonNeededForUser(USERID_ONE));
- assertFalse(fsc.isDungeonNeededForUser(USERID_TWO));
+ entryRemoved(makeMockDisclosure(USERID_TWO, null /*unused*/));
+ assertFalse(mFsc.isDisclosureNeededForUser(USERID_ONE));
+ assertFalse(mFsc.isDisclosureNeededForUser(USERID_TWO));
}
@Test
- public void testDungeonBasic() {
+ public void testDisclosureBasic() {
final String PKG1 = "com.example.app0";
StatusBarNotification sbn_user1_app1 = makeMockSBN(USERID_ONE, PKG1,
5000, "monkeys", Notification.FLAG_AUTO_CANCEL);
StatusBarNotification sbn_user1_app1_fg = makeMockFgSBN(USERID_ONE, PKG1);
- fsc.addNotification(sbn_user1_app1, NotificationManager.IMPORTANCE_DEFAULT); // not fg
- fsc.addNotification(makeMockDungeon(USERID_ONE, new String[]{ PKG1 }),
+ entryAdded(sbn_user1_app1, NotificationManager.IMPORTANCE_DEFAULT); // not fg
+ entryAdded(makeMockDisclosure(USERID_ONE, new String[]{PKG1}),
NotificationManager.IMPORTANCE_DEFAULT);
- assertTrue(fsc.isDungeonNeededForUser(USERID_ONE)); // should be required!
- fsc.addNotification(sbn_user1_app1_fg, NotificationManager.IMPORTANCE_DEFAULT);
- assertFalse(fsc.isDungeonNeededForUser(USERID_ONE)); // app1 has got it covered
- assertFalse(fsc.isDungeonNeededForUser(USERID_TWO));
+ assertTrue(mFsc.isDisclosureNeededForUser(USERID_ONE)); // should be required!
+ entryAdded(sbn_user1_app1_fg, NotificationManager.IMPORTANCE_DEFAULT);
+ assertFalse(mFsc.isDisclosureNeededForUser(USERID_ONE)); // app1 has got it covered
+ assertFalse(mFsc.isDisclosureNeededForUser(USERID_TWO));
// let's take out the other notification and see what happens.
- fsc.removeNotification(sbn_user1_app1);
- assertFalse(fsc.isDungeonNeededForUser(USERID_ONE)); // still covered by sbn_user1_app1_fg
- assertFalse(fsc.isDungeonNeededForUser(USERID_TWO));
+ entryRemoved(sbn_user1_app1);
+ assertFalse(
+ mFsc.isDisclosureNeededForUser(USERID_ONE)); // still covered by sbn_user1_app1_fg
+ assertFalse(mFsc.isDisclosureNeededForUser(USERID_TWO));
// let's attempt to downgrade the notification from FLAG_FOREGROUND and see what we get
StatusBarNotification sbn_user1_app1_fg_sneaky = makeMockFgSBN(USERID_ONE, PKG1);
sbn_user1_app1_fg_sneaky.getNotification().flags = 0;
- fsc.updateNotification(sbn_user1_app1_fg_sneaky, NotificationManager.IMPORTANCE_DEFAULT);
- assertTrue(fsc.isDungeonNeededForUser(USERID_ONE)); // should be required!
- assertFalse(fsc.isDungeonNeededForUser(USERID_TWO));
+ entryUpdated(sbn_user1_app1_fg_sneaky,
+ NotificationManager.IMPORTANCE_DEFAULT);
+ assertTrue(mFsc.isDisclosureNeededForUser(USERID_ONE)); // should be required!
+ assertFalse(mFsc.isDisclosureNeededForUser(USERID_TWO));
// ok, ok, we'll put it back
sbn_user1_app1_fg_sneaky.getNotification().flags = Notification.FLAG_FOREGROUND_SERVICE;
- fsc.updateNotification(sbn_user1_app1_fg, NotificationManager.IMPORTANCE_DEFAULT);
- assertFalse(fsc.isDungeonNeededForUser(USERID_ONE));
- assertFalse(fsc.isDungeonNeededForUser(USERID_TWO));
+ entryUpdated(sbn_user1_app1_fg, NotificationManager.IMPORTANCE_DEFAULT);
+ assertFalse(mFsc.isDisclosureNeededForUser(USERID_ONE));
+ assertFalse(mFsc.isDisclosureNeededForUser(USERID_TWO));
- assertTrue(fsc.removeNotification(sbn_user1_app1_fg_sneaky));
- assertTrue(fsc.isDungeonNeededForUser(USERID_ONE)); // should be required!
- assertFalse(fsc.isDungeonNeededForUser(USERID_TWO));
+ entryRemoved(sbn_user1_app1_fg_sneaky);
+ assertTrue(mFsc.isDisclosureNeededForUser(USERID_ONE)); // should be required!
+ assertFalse(mFsc.isDisclosureNeededForUser(USERID_TWO));
// now let's test an upgrade
- fsc.addNotification(sbn_user1_app1, NotificationManager.IMPORTANCE_DEFAULT);
- assertTrue(fsc.isDungeonNeededForUser(USERID_ONE));
- assertFalse(fsc.isDungeonNeededForUser(USERID_TWO));
+ entryAdded(sbn_user1_app1, NotificationManager.IMPORTANCE_DEFAULT);
+ assertTrue(mFsc.isDisclosureNeededForUser(USERID_ONE));
+ assertFalse(mFsc.isDisclosureNeededForUser(USERID_TWO));
sbn_user1_app1.getNotification().flags |= Notification.FLAG_FOREGROUND_SERVICE;
- fsc.updateNotification(sbn_user1_app1,
+ entryUpdated(sbn_user1_app1,
NotificationManager.IMPORTANCE_DEFAULT); // this is now a fg notification
- assertFalse(fsc.isDungeonNeededForUser(USERID_TWO));
- assertFalse(fsc.isDungeonNeededForUser(USERID_ONE));
+ assertFalse(mFsc.isDisclosureNeededForUser(USERID_TWO));
+ assertFalse(mFsc.isDisclosureNeededForUser(USERID_ONE));
// remove it, make sure we're out of compliance again
- assertTrue(fsc.removeNotification(sbn_user1_app1)); // was fg, should return true
- assertFalse(fsc.removeNotification(sbn_user1_app1));
- assertFalse(fsc.isDungeonNeededForUser(USERID_TWO));
- assertTrue(fsc.isDungeonNeededForUser(USERID_ONE));
+ entryRemoved(sbn_user1_app1); // was fg, should return true
+ entryRemoved(sbn_user1_app1);
+ assertFalse(mFsc.isDisclosureNeededForUser(USERID_TWO));
+ assertTrue(mFsc.isDisclosureNeededForUser(USERID_ONE));
// importance upgrade
- fsc.addNotification(sbn_user1_app1_fg, NotificationManager.IMPORTANCE_MIN);
- assertTrue(fsc.isDungeonNeededForUser(USERID_ONE));
- assertFalse(fsc.isDungeonNeededForUser(USERID_TWO));
+ entryAdded(sbn_user1_app1_fg, NotificationManager.IMPORTANCE_MIN);
+ assertTrue(mFsc.isDisclosureNeededForUser(USERID_ONE));
+ assertFalse(mFsc.isDisclosureNeededForUser(USERID_TWO));
sbn_user1_app1.getNotification().flags |= Notification.FLAG_FOREGROUND_SERVICE;
- fsc.updateNotification(sbn_user1_app1_fg,
+ entryUpdated(sbn_user1_app1_fg,
NotificationManager.IMPORTANCE_DEFAULT); // this is now a fg notification
// finally, let's turn off the service
- fsc.addNotification(makeMockDungeon(USERID_ONE, null),
+ entryAdded(makeMockDisclosure(USERID_ONE, null),
NotificationManager.IMPORTANCE_DEFAULT);
- assertFalse(fsc.isDungeonNeededForUser(USERID_ONE));
- assertFalse(fsc.isDungeonNeededForUser(USERID_TWO));
+ assertFalse(mFsc.isDisclosureNeededForUser(USERID_ONE));
+ assertFalse(mFsc.isDisclosureNeededForUser(USERID_TWO));
}
@Test
@@ -375,8 +276,8 @@
StatusBarNotification sbn_user1_overlay = makeMockSBN(USERID_ONE, "android",
0, "AlertWindowNotification", Notification.FLAG_NO_CLEAR);
- assertTrue(fsc.isSystemAlertNotification(sbn_user1_overlay));
- assertFalse(fsc.isSystemAlertNotification(sbn_user1_app1));
+ assertTrue(mFsc.isSystemAlertNotification(sbn_user1_overlay));
+ assertFalse(mFsc.isSystemAlertNotification(sbn_user1_app1));
}
@Test
@@ -386,54 +287,54 @@
StatusBarNotification sbn_user1_app1 = makeMockFgSBN(USERID_ONE, PKG1, 0, true);
sbn_user1_app1.getNotification().flags = 0;
StatusBarNotification sbn_user1_app1_fg = makeMockFgSBN(USERID_ONE, PKG1, 1, true);
- fsc.addNotification(sbn_user1_app1, NotificationManager.IMPORTANCE_MIN); // not fg
- assertTrue(fsc.isSystemAlertWarningNeeded(USERID_ONE, PKG1)); // should be required!
- fsc.addNotification(sbn_user1_app1_fg, NotificationManager.IMPORTANCE_MIN);
- assertFalse(fsc.isSystemAlertWarningNeeded(USERID_ONE, PKG1)); // app1 has got it covered
- assertFalse(fsc.isSystemAlertWarningNeeded(USERID_TWO, "otherpkg"));
+ entryAdded(sbn_user1_app1, NotificationManager.IMPORTANCE_MIN); // not fg
+ assertTrue(mFsc.isSystemAlertWarningNeeded(USERID_ONE, PKG1)); // should be required!
+ entryAdded(sbn_user1_app1_fg, NotificationManager.IMPORTANCE_MIN);
+ assertFalse(mFsc.isSystemAlertWarningNeeded(USERID_ONE, PKG1)); // app1 has got it covered
+ assertFalse(mFsc.isSystemAlertWarningNeeded(USERID_TWO, "otherpkg"));
// let's take out the non-fg notification and see what happens.
- fsc.removeNotification(sbn_user1_app1);
+ entryRemoved(sbn_user1_app1);
// still covered by sbn_user1_app1_fg
- assertFalse(fsc.isSystemAlertWarningNeeded(USERID_ONE, PKG1));
- assertFalse(fsc.isSystemAlertWarningNeeded(USERID_TWO, "anyPkg"));
+ assertFalse(mFsc.isSystemAlertWarningNeeded(USERID_ONE, PKG1));
+ assertFalse(mFsc.isSystemAlertWarningNeeded(USERID_TWO, "anyPkg"));
// let's attempt to downgrade the notification from FLAG_FOREGROUND and see what we get
StatusBarNotification sbn_user1_app1_fg_sneaky = makeMockFgSBN(USERID_ONE, PKG1, 1, true);
sbn_user1_app1_fg_sneaky.getNotification().flags = 0;
- fsc.updateNotification(sbn_user1_app1_fg_sneaky, NotificationManager.IMPORTANCE_MIN);
- assertTrue(fsc.isSystemAlertWarningNeeded(USERID_ONE, PKG1)); // should be required!
- assertFalse(fsc.isSystemAlertWarningNeeded(USERID_TWO, "anything"));
+ entryUpdated(sbn_user1_app1_fg_sneaky, NotificationManager.IMPORTANCE_MIN);
+ assertTrue(mFsc.isSystemAlertWarningNeeded(USERID_ONE, PKG1)); // should be required!
+ assertFalse(mFsc.isSystemAlertWarningNeeded(USERID_TWO, "anything"));
// ok, ok, we'll put it back
sbn_user1_app1_fg_sneaky.getNotification().flags = Notification.FLAG_FOREGROUND_SERVICE;
- fsc.updateNotification(sbn_user1_app1_fg, NotificationManager.IMPORTANCE_MIN);
- assertFalse(fsc.isSystemAlertWarningNeeded(USERID_ONE, PKG1));
- assertFalse(fsc.isSystemAlertWarningNeeded(USERID_TWO, "whatever"));
+ entryUpdated(sbn_user1_app1_fg, NotificationManager.IMPORTANCE_MIN);
+ assertFalse(mFsc.isSystemAlertWarningNeeded(USERID_ONE, PKG1));
+ assertFalse(mFsc.isSystemAlertWarningNeeded(USERID_TWO, "whatever"));
- assertTrue(fsc.removeNotification(sbn_user1_app1_fg_sneaky));
- assertTrue(fsc.isSystemAlertWarningNeeded(USERID_ONE, PKG1)); // should be required!
- assertFalse(fsc.isSystemAlertWarningNeeded(USERID_TWO, "a"));
+ entryRemoved(sbn_user1_app1_fg_sneaky);
+ assertTrue(mFsc.isSystemAlertWarningNeeded(USERID_ONE, PKG1)); // should be required!
+ assertFalse(mFsc.isSystemAlertWarningNeeded(USERID_TWO, "a"));
// let's try a custom layout
sbn_user1_app1_fg_sneaky = makeMockFgSBN(USERID_ONE, PKG1, 1, false);
- fsc.updateNotification(sbn_user1_app1_fg_sneaky, NotificationManager.IMPORTANCE_MIN);
- assertTrue(fsc.isSystemAlertWarningNeeded(USERID_ONE, PKG1)); // should be required!
- assertFalse(fsc.isSystemAlertWarningNeeded(USERID_TWO, "anything"));
+ entryUpdated(sbn_user1_app1_fg_sneaky, NotificationManager.IMPORTANCE_MIN);
+ assertTrue(mFsc.isSystemAlertWarningNeeded(USERID_ONE, PKG1)); // should be required!
+ assertFalse(mFsc.isSystemAlertWarningNeeded(USERID_TWO, "anything"));
// now let's test an upgrade (non fg to fg)
- fsc.addNotification(sbn_user1_app1, NotificationManager.IMPORTANCE_MIN);
- assertTrue(fsc.isSystemAlertWarningNeeded(USERID_ONE, PKG1));
- assertFalse(fsc.isSystemAlertWarningNeeded(USERID_TWO, "b"));
+ entryAdded(sbn_user1_app1, NotificationManager.IMPORTANCE_MIN);
+ assertTrue(mFsc.isSystemAlertWarningNeeded(USERID_ONE, PKG1));
+ assertFalse(mFsc.isSystemAlertWarningNeeded(USERID_TWO, "b"));
sbn_user1_app1.getNotification().flags |= Notification.FLAG_FOREGROUND_SERVICE;
- fsc.updateNotification(sbn_user1_app1,
+ entryUpdated(sbn_user1_app1,
NotificationManager.IMPORTANCE_MIN); // this is now a fg notification
- assertFalse(fsc.isSystemAlertWarningNeeded(USERID_TWO, PKG1));
- assertFalse(fsc.isSystemAlertWarningNeeded(USERID_ONE, PKG1));
+ assertFalse(mFsc.isSystemAlertWarningNeeded(USERID_TWO, PKG1));
+ assertFalse(mFsc.isSystemAlertWarningNeeded(USERID_ONE, PKG1));
// remove it, make sure we're out of compliance again
- assertTrue(fsc.removeNotification(sbn_user1_app1)); // was fg, should return true
- assertFalse(fsc.removeNotification(sbn_user1_app1));
- assertFalse(fsc.isSystemAlertWarningNeeded(USERID_TWO, PKG1));
- assertTrue(fsc.isSystemAlertWarningNeeded(USERID_ONE, PKG1));
+ entryRemoved(sbn_user1_app1); // was fg, should return true
+ entryRemoved(sbn_user1_app1);
+ assertFalse(mFsc.isSystemAlertWarningNeeded(USERID_TWO, PKG1));
+ assertTrue(mFsc.isSystemAlertWarningNeeded(USERID_ONE, PKG1));
}
private StatusBarNotification makeMockSBN(int userid, String pkg, int id, String tag,
@@ -475,7 +376,7 @@
return makeMockSBN(userid, pkg, 1000, "foo", Notification.FLAG_FOREGROUND_SERVICE);
}
- private StatusBarNotification makeMockDungeon(int userid, String[] pkgs) {
+ private StatusBarNotification makeMockDisclosure(int userid, String[] pkgs) {
final Notification n = mock(Notification.class);
n.flags = Notification.FLAG_ONGOING_EVENT;
final Bundle extras = new Bundle();
@@ -488,4 +389,21 @@
sbn.getNotification().extras = extras;
return sbn;
}
+
+ private void entryRemoved(StatusBarNotification notification) {
+ mEntryListener.onEntryRemoved(new NotificationData.Entry(notification),
+ null, null, null, false, false);
+ }
+
+ private void entryAdded(StatusBarNotification notification, int importance) {
+ NotificationData.Entry entry = new NotificationData.Entry(notification);
+ entry.importance = importance;
+ mEntryListener.onPendingEntryAdded(entry);
+ }
+
+ private void entryUpdated(StatusBarNotification notification, int importance) {
+ NotificationData.Entry entry = new NotificationData.Entry(notification);
+ entry.importance = importance;
+ mEntryListener.onEntryUpdated(entry);
+ }
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/QSFragmentTest.java b/packages/SystemUI/tests/src/com/android/systemui/qs/QSFragmentTest.java
index 2cb326e..823485f 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/qs/QSFragmentTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/qs/QSFragmentTest.java
@@ -39,6 +39,7 @@
import com.android.systemui.SysuiBaseFragmentTest;
import com.android.systemui.qs.tileimpl.QSFactoryImpl;
import com.android.systemui.shared.plugins.PluginManager;
+import com.android.systemui.statusbar.phone.AutoTileManager;
import com.android.systemui.statusbar.phone.StatusBarIconController;
import com.android.systemui.statusbar.policy.Clock;
import com.android.systemui.statusbar.policy.ConfigurationController;
@@ -92,7 +93,8 @@
processAllMessages();
QSTileHost host = new QSTileHost(mContext, mock(StatusBarIconController.class),
mock(QSFactoryImpl.class), new Handler(), Looper.myLooper(),
- mock(PluginManager.class), mock(TunerService.class));
+ mock(PluginManager.class), mock(TunerService.class),
+ () -> mock(AutoTileManager.class));
qs.setHost(host);
qs.setListening(true);
diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/external/TileServicesTest.java b/packages/SystemUI/tests/src/com/android/systemui/qs/external/TileServicesTest.java
index 63f4bbc..03278b4 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/qs/external/TileServicesTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/qs/external/TileServicesTest.java
@@ -33,6 +33,7 @@
import com.android.systemui.qs.QSTileHost;
import com.android.systemui.qs.tileimpl.QSFactoryImpl;
import com.android.systemui.shared.plugins.PluginManager;
+import com.android.systemui.statusbar.phone.AutoTileManager;
import com.android.systemui.statusbar.phone.StatusBarIconController;
import com.android.systemui.statusbar.policy.BluetoothController;
import com.android.systemui.tuner.TunerService;
@@ -65,7 +66,8 @@
new Handler(),
Looper.myLooper(),
mock(PluginManager.class),
- mock(TunerService.class));
+ mock(TunerService.class),
+ () -> mock(AutoTileManager.class));
mTileService = new TestTileServices(host, Looper.getMainLooper());
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationEntryManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationEntryManagerTest.java
index a2d408e..57c9d29 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationEntryManagerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationEntryManagerTest.java
@@ -256,7 +256,6 @@
// Check that no inflation error occurred.
verify(mEntryListener, never()).onInflationError(any(), any());
- verify(mForegroundServiceController).addNotification(eq(mSbn), anyInt());
// Row inflation:
ArgumentCaptor<NotificationData.Entry> entryCaptor = ArgumentCaptor.forClass(
@@ -292,7 +291,6 @@
verify(mEntryListener, never()).onInflationError(any(), any());
verify(mPresenter).updateNotificationViews();
- verify(mForegroundServiceController).updateNotification(eq(mSbn), anyInt());
verify(mEntryListener).onEntryUpdated(mEntry);
assertNotNull(mEntry.getRow());
assertEquals(mEntry.userSentiment,
@@ -310,7 +308,6 @@
verify(mEntryListener, never()).onInflationError(any(), any());
- verify(mForegroundServiceController).removeNotification(mSbn);
verify(mListContainer).cleanUpViewStateForEntry(mEntry);
verify(mPresenter).updateNotificationViews();
verify(mEntryListener).onEntryRemoved(mEntry, mSbn.getKey(), mSbn,
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayoutTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayoutTest.java
index b8c7ee0..b66d0ab 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayoutTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayoutTest.java
@@ -35,12 +35,7 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import android.os.Handler;
-import android.os.IPowerManager;
-import android.os.Looper;
-import android.os.PowerManager;
import android.provider.Settings;
-import android.service.dreams.IDreamManager;
import android.support.test.annotation.UiThreadTest;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
@@ -104,8 +99,6 @@
@Mock private NotificationData mNotificationData;
@Mock private NotificationRemoteInputManager mRemoteInputManager;
@Mock private RemoteInputController mRemoteInputController;
- @Mock private IDreamManager mDreamManager;
- private PowerManager mPowerManager;
private TestableNotificationEntryManager mEntryManager;
private int mOriginalInterruptionModelSetting;
@@ -122,12 +115,7 @@
mDependency.injectMockDependency(ShadeController.class);
when(mRemoteInputManager.getController()).thenReturn(mRemoteInputController);
- IPowerManager powerManagerService = mock(IPowerManager.class);
- mPowerManager = new PowerManager(mContext, powerManagerService,
- Handler.createAsync(Looper.myLooper()));
-
- mEntryManager = new TestableNotificationEntryManager(mPowerManager,
- mContext);
+ mEntryManager = new TestableNotificationEntryManager(mContext);
mDependency.injectTestDependency(NotificationEntryManager.class, mEntryManager);
Dependency.get(InitController.class).executePostInitTasks();
mEntryManager.setUpForTest(mock(NotificationPresenter.class), null, mHeadsUpManager,
@@ -135,7 +123,8 @@
NotificationShelf notificationShelf = mock(NotificationShelf.class);
- mStackScroller = spy(new NotificationStackScrollLayout(getContext()));
+ mStackScroller = spy(new NotificationStackScrollLayout(getContext(), null,
+ true /* allowLongPress */));
mStackScroller.setShelf(notificationShelf);
mStackScroller.setStatusBar(mBar);
mStackScroller.setScrimController(mock(ScrimController.class));
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/AutoTileManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/AutoTileManagerTest.java
index 1481aef..c0f7f0c 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/AutoTileManagerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/AutoTileManagerTest.java
@@ -16,6 +16,7 @@
package com.android.systemui.statusbar.phone;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
@@ -30,6 +31,8 @@
import com.android.systemui.SysuiTestCase;
import com.android.systemui.qs.AutoAddTracker;
import com.android.systemui.qs.QSTileHost;
+import com.android.systemui.statusbar.policy.DataSaverController;
+import com.android.systemui.statusbar.policy.HotspotController;
import org.junit.Before;
import org.junit.Test;
@@ -51,7 +54,11 @@
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
mAutoTileManager = new AutoTileManager(mContext, mAutoAddTracker, mQsTileHost,
- Handler.createAsync(TestableLooper.get(this).getLooper()));
+ Handler.createAsync(TestableLooper.get(this).getLooper()),
+ mock(HotspotController.class),
+ mock(DataSaverController.class),
+ mock(ManagedProfileController.class),
+ mock(ColorDisplayController.class));
}
@Test
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarTest.java
index d57d565..a45a5c4 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarTest.java
@@ -205,7 +205,7 @@
mMetricsLogger = new FakeMetricsLogger();
mDependency.injectTestDependency(MetricsLogger.class, mMetricsLogger);
- mEntryManager = new TestableNotificationEntryManager(mPowerManager, mContext);
+ mEntryManager = new TestableNotificationEntryManager(mContext);
mNotificationLogger = new NotificationLogger(mNotificationListener,
Dependency.get(UiOffloadThread.class), mEntryManager, mStatusBarStateController);
mDependency.injectTestDependency(NotificationLogger.class, mNotificationLogger);
@@ -761,9 +761,8 @@
public static class TestableNotificationEntryManager extends NotificationEntryManager {
- public TestableNotificationEntryManager(PowerManager powerManager, Context context) {
+ public TestableNotificationEntryManager(Context context) {
super(context);
- mPowerManager = powerManager;
}
public void setUpForTest(NotificationPresenter presenter,
diff --git a/packages/overlays/AccentColorBlackOverlay/res/values/strings.xml b/packages/overlays/AccentColorBlackOverlay/res/values/strings.xml
index baf09b1..da10361 100644
--- a/packages/overlays/AccentColorBlackOverlay/res/values/strings.xml
+++ b/packages/overlays/AccentColorBlackOverlay/res/values/strings.xml
@@ -18,6 +18,6 @@
-->
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<!-- Black accent color name application label. [CHAR LIMIT=50] -->
- <string name="accent_color_black_overlay" translatable="false">Black Accent Color</string>
+ <string name="accent_color_black_overlay" translatable="false">Black</string>
</resources>
diff --git a/packages/overlays/AccentColorGreenOverlay/res/values/strings.xml b/packages/overlays/AccentColorGreenOverlay/res/values/strings.xml
index 4de344c..623a1da 100644
--- a/packages/overlays/AccentColorGreenOverlay/res/values/strings.xml
+++ b/packages/overlays/AccentColorGreenOverlay/res/values/strings.xml
@@ -18,6 +18,6 @@
-->
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<!-- Green accent color name application label. [CHAR LIMIT=50] -->
- <string name="accent_color_green_overlay" translatable="false">Green Accent Color</string>
+ <string name="accent_color_green_overlay" translatable="false">Green</string>
</resources>
diff --git a/packages/overlays/AccentColorPurpleOverlay/res/values/strings.xml b/packages/overlays/AccentColorPurpleOverlay/res/values/strings.xml
index d1eb95a..d1c7168 100644
--- a/packages/overlays/AccentColorPurpleOverlay/res/values/strings.xml
+++ b/packages/overlays/AccentColorPurpleOverlay/res/values/strings.xml
@@ -18,6 +18,6 @@
-->
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<!-- Purple accent color name application label. [CHAR LIMIT=50] -->
- <string name="accent_color_purple_overlay" translatable="false">Purple Accent Color</string>
+ <string name="accent_color_purple_overlay" translatable="false">Purple</string>
</resources>
diff --git a/packages/overlays/IconShapeRoundedRectOverlay/res/values/strings.xml b/packages/overlays/IconShapeRoundedRectOverlay/res/values/strings.xml
index dc5c196..3c4c24d 100644
--- a/packages/overlays/IconShapeRoundedRectOverlay/res/values/strings.xml
+++ b/packages/overlays/IconShapeRoundedRectOverlay/res/values/strings.xml
@@ -18,6 +18,6 @@
-->
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<!-- Rounded corner rectangle overlay -->
- <string name="icon_shape_roundedrect_overlay" translatable="false">RoundedRectangle Icons</string>
+ <string name="icon_shape_roundedrect_overlay" translatable="false">Rounded Rectangle</string>
</resources>
diff --git a/packages/overlays/IconShapeSquareOverlay/res/values/strings.xml b/packages/overlays/IconShapeSquareOverlay/res/values/strings.xml
index 4fd39ff26..5772165 100644
--- a/packages/overlays/IconShapeSquareOverlay/res/values/strings.xml
+++ b/packages/overlays/IconShapeSquareOverlay/res/values/strings.xml
@@ -18,6 +18,6 @@
-->
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<!-- Square icon overlay -->
- <string name="icon_shape_square_overlay" translatable="false">Square Icons</string>
+ <string name="icon_shape_square_overlay" translatable="false">Square</string>
</resources>
diff --git a/packages/overlays/IconShapeSquircleOverlay/res/values/strings.xml b/packages/overlays/IconShapeSquircleOverlay/res/values/strings.xml
index b7c001c..028eccb 100644
--- a/packages/overlays/IconShapeSquircleOverlay/res/values/strings.xml
+++ b/packages/overlays/IconShapeSquircleOverlay/res/values/strings.xml
@@ -18,6 +18,6 @@
-->
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<!-- Squircle icon shape overlay -->
- <string name="icon_shape_squircle_overlay" translatable="false">Square Icons</string>
+ <string name="icon_shape_squircle_overlay" translatable="false">Squircle</string>
</resources>
diff --git a/packages/overlays/IconShapeTeardropOverlay/res/values/strings.xml b/packages/overlays/IconShapeTeardropOverlay/res/values/strings.xml
index d946ee8..db9fa98 100644
--- a/packages/overlays/IconShapeTeardropOverlay/res/values/strings.xml
+++ b/packages/overlays/IconShapeTeardropOverlay/res/values/strings.xml
@@ -18,6 +18,6 @@
-->
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<!-- Teardrop icon overlay -->
- <string name="icon_shape_teardrop_overlay" translatable="false">Teardrop Icons</string>
+ <string name="icon_shape_teardrop_overlay" translatable="false">Teardrop</string>
</resources>
diff --git a/services/core/java/com/android/server/PackageWatchdog.java b/services/core/java/com/android/server/PackageWatchdog.java
index 06dc918..f27d373 100644
--- a/services/core/java/com/android/server/PackageWatchdog.java
+++ b/services/core/java/com/android/server/PackageWatchdog.java
@@ -19,10 +19,7 @@
import android.content.Context;
import android.os.Environment;
import android.os.Handler;
-import android.os.HandlerThread;
import android.os.Looper;
-import android.os.Message;
-import android.os.Process;
import android.os.SystemClock;
import android.text.TextUtils;
import android.util.ArrayMap;
@@ -32,6 +29,7 @@
import android.util.Xml;
import com.android.internal.annotations.GuardedBy;
+import com.android.internal.os.BackgroundThread;
import com.android.internal.util.FastXmlSerializer;
import com.android.internal.util.XmlUtils;
@@ -50,8 +48,6 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-import java.util.Map;
-import java.util.concurrent.TimeUnit;
/**
* Monitors the health of packages on the system and notifies interested observers when packages
@@ -70,7 +66,6 @@
private static final String ATTR_VERSION = "version";
private static final String ATTR_NAME = "name";
private static final String ATTR_DURATION = "duration";
- private static final int MESSAGE_SAVE_FILE = 1;
private static PackageWatchdog sPackageWatchdog;
@@ -79,20 +74,21 @@
private final Context mContext;
// Handler to run package cleanup runnables
private final Handler mTimerHandler;
- private final HandlerThread mIoThread = new HandlerThread("package_watchdog_io",
- Process.THREAD_PRIORITY_BACKGROUND);
private final Handler mIoHandler;
- // Maps observer names to package observers that have been registered since the last boot
+ // Contains (observer-name -> external-observer-handle) that have been registered during the
+ // current boot.
+ // It is populated when observers call #registerHealthObserver and it does not survive reboots.
@GuardedBy("mLock")
- final Map<String, PackageHealthObserver> mRegisteredObservers = new ArrayMap<>();
- // Maps observer names to internal observers (registered or not) loaded from file
+ final ArrayMap<String, PackageHealthObserver> mRegisteredObservers = new ArrayMap<>();
+ // Contains (observer-name -> internal-observer-handle) that have ever been registered from
+ // previous boots. Observers with all packages expired are periodically pruned.
+ // It is saved to disk on system shutdown and repouplated on startup so it survives reboots.
@GuardedBy("mLock")
- final Map<String, ObserverInternal> mAllObservers = new ArrayMap<>();
- // /data/system/ directory
- private final File mSystemDir = new File(Environment.getDataDirectory(), "system");
- // File containing the XML data of monitored packages
+ final ArrayMap<String, ObserverInternal> mAllObservers = new ArrayMap<>();
+ // File containing the XML data of monitored packages /data/system/package-watchdog.xml
private final AtomicFile mPolicyFile =
- new AtomicFile(new File(mSystemDir, "package-watchdog.xml"));
+ new AtomicFile(new File(new File(Environment.getDataDirectory(), "system"),
+ "package-watchdog.xml"));
// Runnable to prune monitored packages that have expired
private final Runnable mPackageCleanup;
// Last SystemClock#uptimeMillis a package clean up was executed.
@@ -105,18 +101,19 @@
private PackageWatchdog(Context context) {
mContext = context;
mTimerHandler = new Handler(Looper.myLooper());
- mIoThread.start();
- mIoHandler = new IoHandler(mIoThread.getLooper());
+ mIoHandler = BackgroundThread.getHandler();
mPackageCleanup = this::rescheduleCleanup;
loadFromFile();
}
/** Creates or gets singleton instance of PackageWatchdog. */
- public static synchronized PackageWatchdog getInstance(Context context) {
- if (sPackageWatchdog == null) {
- sPackageWatchdog = new PackageWatchdog(context);
+ public static PackageWatchdog getInstance(Context context) {
+ synchronized (PackageWatchdog.class) {
+ if (sPackageWatchdog == null) {
+ sPackageWatchdog = new PackageWatchdog(context);
+ }
+ return sPackageWatchdog;
}
- return sPackageWatchdog;
}
/**
@@ -140,21 +137,20 @@
* {@code observer} of any package failures within the monitoring duration.
*
* <p>If {@code observer} is already monitoring a package in {@code packageNames},
- * the monitoring window of that package will be reset to {@code hours}.
+ * the monitoring window of that package will be reset to {@code durationMs}.
*
* @throws IllegalArgumentException if {@code packageNames} is empty
- * or {@code hours} is less than 1
+ * or {@code durationMs} is less than 1
*/
public void startObservingHealth(PackageHealthObserver observer, List<String> packageNames,
- int hours) {
- if (packageNames.isEmpty() || hours < 1) {
+ int durationMs) {
+ if (packageNames.isEmpty() || durationMs < 1) {
throw new IllegalArgumentException("Observation not started, no packages specified"
- + "or invalid hours");
+ + "or invalid duration");
}
- long durationMs = TimeUnit.HOURS.toMillis(hours);
List<MonitoredPackage> packages = new ArrayList<>();
- for (String packageName : packageNames) {
- packages.add(new MonitoredPackage(packageName, durationMs));
+ for (int i = 0; i < packageNames.size(); i++) {
+ packages.add(new MonitoredPackage(packageNames.get(i), durationMs));
}
synchronized (mLock) {
ObserverInternal oldObserver = mAllObservers.get(observer.getName());
@@ -173,7 +169,7 @@
// Always reschedule because we may need to expire packages
// earlier than we are already scheduled for
rescheduleCleanup();
- sendIoMessage(MESSAGE_SAVE_FILE);
+ saveToFileAsync();
}
/**
@@ -186,7 +182,7 @@
mAllObservers.remove(observer.getName());
mRegisteredObservers.remove(observer.getName());
}
- sendIoMessage(MESSAGE_SAVE_FILE);
+ saveToFileAsync();
}
// TODO(zezeozue:) Accept current versionCodes of failing packages?
@@ -194,27 +190,43 @@
* Called when a process fails either due to a crash or ANR.
*
* <p>All registered observers for the packages contained in the process will be notified in
- * order of priority unitl an observer signifies that it has taken action and other observers
+ * order of priority until an observer signifies that it has taken action and other observers
* should not notified.
*
* <p>This method could be called frequently if there is a severe problem on the device.
*/
public void onPackageFailure(String[] packages) {
+ ArrayMap<String, List<PackageHealthObserver>> packagesToReport = new ArrayMap<>();
synchronized (mLock) {
if (mRegisteredObservers.isEmpty()) {
return;
}
- for (String packageName : packages) {
- for (ObserverInternal observer : mAllObservers.values()) {
- if (observer.onPackageFailure(packageName)) {
- PackageHealthObserver activeObserver =
- mRegisteredObservers.get(observer.mName);
- if (activeObserver != null
- && activeObserver.onHealthCheckFailed(packageName)) {
- // Observer has handled, do not notify other observers
- break;
- }
+
+ for (int pIndex = 0; pIndex < packages.length; pIndex++) {
+ for (int oIndex = 0; oIndex < mAllObservers.size(); oIndex++) {
+ // Observers interested in receiving packageName failures
+ List<PackageHealthObserver> observersToNotify = new ArrayList<>();
+ PackageHealthObserver activeObserver =
+ mRegisteredObservers.get(mAllObservers.valueAt(oIndex).mName);
+ if (activeObserver != null) {
+ observersToNotify.add(activeObserver);
}
+
+ // Save interested observers and notify them outside the lock
+ if (!observersToNotify.isEmpty()) {
+ packagesToReport.put(packages[pIndex], observersToNotify);
+ }
+ }
+ }
+ }
+
+ // Notify observers
+ for (int pIndex = 0; pIndex < packagesToReport.size(); pIndex++) {
+ List<PackageHealthObserver> observers = packagesToReport.valueAt(pIndex);
+ for (int oIndex = 0; oIndex < observers.size(); oIndex++) {
+ if (observers.get(oIndex).onHealthCheckFailed(packages[pIndex])) {
+ // Observer has handled, do not notify others
+ break;
}
}
}
@@ -225,7 +237,7 @@
/** Writes the package information to file during shutdown. */
public void writeNow() {
if (!mAllObservers.isEmpty()) {
- mIoHandler.removeMessages(MESSAGE_SAVE_FILE);
+ mIoHandler.removeCallbacks(this::saveToFile);
pruneObservers(SystemClock.uptimeMillis() - mUptimeAtLastRescheduleMs);
saveToFile();
Slog.i(TAG, "Last write to update package durations");
@@ -235,7 +247,7 @@
/** Register instances of this interface to receive notifications on package failure. */
public interface PackageHealthObserver {
/**
- * Called when health check fails for the {@code packages}.
+ * Called when health check fails for the {@code packageName}.
* @return {@code true} if action was taken and other observers should not be notified of
* this failure, {@code false} otherwise.
*/
@@ -283,10 +295,12 @@
*/
private long getEarliestPackageExpiryLocked() {
long shortestDurationMs = Long.MAX_VALUE;
- for (ObserverInternal observer : mAllObservers.values()) {
- for (MonitoredPackage p : observer.mPackages.values()) {
- if (p.mDurationMs < shortestDurationMs) {
- shortestDurationMs = p.mDurationMs;
+ for (int oIndex = 0; oIndex < mAllObservers.size(); oIndex++) {
+ ArrayMap<String, MonitoredPackage> packages = mAllObservers.valueAt(oIndex).mPackages;
+ for (int pIndex = 0; pIndex < packages.size(); pIndex++) {
+ long duration = packages.valueAt(pIndex).mDurationMs;
+ if (duration < shortestDurationMs) {
+ shortestDurationMs = duration;
}
}
}
@@ -313,7 +327,7 @@
}
}
}
- sendIoMessage(MESSAGE_SAVE_FILE);
+ saveToFileAsync();
}
/**
@@ -339,59 +353,53 @@
}
} catch (FileNotFoundException e) {
// Nothing to monitor
- } catch (IOException e) {
- Log.wtf(TAG, "Unable to read monitored packages", e);
- } catch (NumberFormatException e) {
- Log.wtf(TAG, "Unable to parse monitored package windows", e);
- } catch (XmlPullParserException e) {
- Log.wtf(TAG, "Unable to parse monitored packages", e);
+ } catch (IOException | NumberFormatException | XmlPullParserException e) {
+ Log.wtf(TAG, "Unable to read monitored packages, deleting file", e);
+ mPolicyFile.delete();
} finally {
IoUtils.closeQuietly(infile);
}
}
/**
- * Persists mAllObservers to file and ignores threshold information.
- *
- * <p>Note that this is <b>not</b> thread safe and should only be called on the
- * single threaded IoHandler.
+ * Persists mAllObservers to file. Threshold information is ignored.
*/
private boolean saveToFile() {
- FileOutputStream stream;
- try {
- stream = mPolicyFile.startWrite();
- } catch (IOException e) {
- Slog.w(TAG, "Cannot update monitored packages", e);
- return false;
- }
-
- try {
- XmlSerializer out = new FastXmlSerializer();
- out.setOutput(stream, StandardCharsets.UTF_8.name());
- out.startDocument(null, true);
- out.startTag(null, TAG_PACKAGE_WATCHDOG);
- out.attribute(null, ATTR_VERSION, Integer.toString(DB_VERSION));
- for (ObserverInternal observer : mAllObservers.values()) {
- observer.write(out);
+ synchronized (mLock) {
+ FileOutputStream stream;
+ try {
+ stream = mPolicyFile.startWrite();
+ } catch (IOException e) {
+ Slog.w(TAG, "Cannot update monitored packages", e);
+ return false;
}
- out.endTag(null, TAG_PACKAGE_WATCHDOG);
- out.endDocument();
- mPolicyFile.finishWrite(stream);
- return true;
- } catch (IOException e) {
- Slog.w(TAG, "Failed to save monitored packages, restoring backup", e);
- mPolicyFile.failWrite(stream);
- return false;
- } finally {
- IoUtils.closeQuietly(stream);
+
+ try {
+ XmlSerializer out = new FastXmlSerializer();
+ out.setOutput(stream, StandardCharsets.UTF_8.name());
+ out.startDocument(null, true);
+ out.startTag(null, TAG_PACKAGE_WATCHDOG);
+ out.attribute(null, ATTR_VERSION, Integer.toString(DB_VERSION));
+ for (int oIndex = 0; oIndex < mAllObservers.size(); oIndex++) {
+ mAllObservers.valueAt(oIndex).write(out);
+ }
+ out.endTag(null, TAG_PACKAGE_WATCHDOG);
+ out.endDocument();
+ mPolicyFile.finishWrite(stream);
+ return true;
+ } catch (IOException e) {
+ Slog.w(TAG, "Failed to save monitored packages, restoring backup", e);
+ mPolicyFile.failWrite(stream);
+ return false;
+ } finally {
+ IoUtils.closeQuietly(stream);
+ }
}
}
- private void sendIoMessage(int what) {
- if (!mIoHandler.hasMessages(what)) {
- Message m = Message.obtain(mIoHandler, what);
- mIoHandler.sendMessage(m);
- }
+ private void saveToFileAsync() {
+ mIoHandler.removeCallbacks(this::saveToFile);
+ mIoHandler.post(this::saveToFile);
}
/**
@@ -435,7 +443,8 @@
public void updatePackages(List<MonitoredPackage> packages) {
synchronized (mName) {
- for (MonitoredPackage p : packages) {
+ for (int pIndex = 0; pIndex < packages.size(); pIndex++) {
+ MonitoredPackage p = packages.get(pIndex);
mPackages.put(p.mName, p);
}
}
@@ -554,19 +563,4 @@
return mFailures >= TRIGGER_FAILURE_COUNT;
}
}
-
- private class IoHandler extends Handler {
- IoHandler(Looper looper) {
- super(looper);
- }
-
- @Override
- public void handleMessage(Message msg) {
- switch (msg.what) {
- case MESSAGE_SAVE_FILE:
- saveToFile();
- break;
- }
- }
- }
}
diff --git a/services/core/java/com/android/server/display/AutomaticBrightnessController.java b/services/core/java/com/android/server/display/AutomaticBrightnessController.java
index 52eccca..78b3c15 100644
--- a/services/core/java/com/android/server/display/AutomaticBrightnessController.java
+++ b/services/core/java/com/android/server/display/AutomaticBrightnessController.java
@@ -17,13 +17,6 @@
package com.android.server.display;
import android.annotation.Nullable;
-import android.app.ActivityManager;
-import android.app.ActivityManager.StackInfo;
-import android.app.ActivityTaskManager;
-import android.app.IActivityTaskManager;
-import android.app.TaskStackListener;
-import android.content.pm.ApplicationInfo;
-import android.content.pm.PackageManagerInternal;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
@@ -34,8 +27,6 @@
import android.os.Looper;
import android.os.Message;
import android.os.PowerManager;
-import android.os.Process;
-import android.os.RemoteException;
import android.os.SystemClock;
import android.os.Trace;
import android.util.EventLog;
@@ -43,15 +34,14 @@
import android.util.Slog;
import android.util.TimeUtils;
-import com.android.internal.os.BackgroundThread;
import com.android.server.EventLogTags;
-import com.android.server.LocalServices;
import java.io.PrintWriter;
class AutomaticBrightnessController {
private static final String TAG = "AutomaticBrightnessController";
+ private static final boolean DEBUG = false;
private static final boolean DEBUG_PRETEND_LIGHT_SENSOR_ABSENT = false;
// If true, enables the use of the screen auto-brightness adjustment setting.
@@ -76,8 +66,6 @@
private static final int MSG_UPDATE_AMBIENT_LUX = 1;
private static final int MSG_BRIGHTNESS_ADJUSTMENT_SAMPLE = 2;
private static final int MSG_INVALIDATE_SHORT_TERM_MODEL = 3;
- private static final int MSG_UPDATE_FOREGROUND_APP = 4;
- private static final int MSG_UPDATE_FOREGROUND_APP_SYNC = 5;
// Length of the ambient light horizon used to calculate the long term estimate of ambient
// light.
@@ -138,8 +126,6 @@
private final HysteresisLevels mAmbientBrightnessThresholds;
private final HysteresisLevels mScreenBrightnessThresholds;
- private boolean mLoggingEnabled;
-
// Amount of time to delay auto-brightness after screen on while waiting for
// the light sensor to warm-up in milliseconds.
// May be 0 if no warm-up is required.
@@ -206,19 +192,6 @@
private float mShortTermModelAnchor;
private float SHORT_TERM_MODEL_THRESHOLD_RATIO = 0.6f;
- // Context-sensitive brightness configurations require keeping track of the foreground app's
- // package name and category, which is done by registering a TaskStackListener to call back to
- // us onTaskStackChanged, and then using the ActivityTaskManager to get the foreground app's
- // package namd and PackageManager to get its category (so might as well cache them).
- private int mUserId;
- private String mForegroundAppPackageName;
- private String mPendingForegroundAppPackageName;
- private @ApplicationInfo.Category int mForegroundAppCategory;
- private @ApplicationInfo.Category int mPendingForegroundAppCategory;
- private TaskStackListenerImpl mTaskStackListener;
- private IActivityTaskManager mActivityTaskManager;
- private PackageManagerInternal mPackageManagerInternal;
-
public AutomaticBrightnessController(Callbacks callbacks, Looper looper,
SensorManager sensorManager, BrightnessMappingStrategy mapper,
int lightSensorWarmUpTime, int brightnessMin, int brightnessMax, float dozeScaleFactor,
@@ -253,42 +226,6 @@
if (!DEBUG_PRETEND_LIGHT_SENSOR_ABSENT) {
mLightSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
}
-
- mUserId = ActivityManager.getCurrentUser();
- mActivityTaskManager = ActivityTaskManager.getService();
- mPackageManagerInternal = LocalServices.getService(PackageManagerInternal.class);
- mTaskStackListener = new TaskStackListenerImpl();
- mForegroundAppPackageName = null;
- mPendingForegroundAppPackageName = null;
- mForegroundAppCategory = ApplicationInfo.CATEGORY_UNDEFINED;
- mPendingForegroundAppCategory = ApplicationInfo.CATEGORY_UNDEFINED;
- }
-
- /**
- * Enable/disable logging.
- *
- * @param loggingEnabled
- * Whether logging should be on/off.
- *
- * @return Whether the method succeeded or not.
- */
- public boolean setLoggingEnabled(boolean loggingEnabled) {
- if (mLoggingEnabled == loggingEnabled) {
- return false;
- }
- mBrightnessMapper.setLoggingEnabled(loggingEnabled);
- mLoggingEnabled = loggingEnabled;
- return true;
- }
-
- /**
- * Update the current user's ID.
- *
- * @param userId
- * The current user's ID.
- */
- public void onSwitchUser(int userId) {
- mUserId = userId;
}
public int getAutomaticScreenBrightness() {
@@ -353,7 +290,7 @@
}
final int oldPolicy = mDisplayPolicy;
mDisplayPolicy = policy;
- if (mLoggingEnabled) {
+ if (DEBUG) {
Slog.d(TAG, "Display policy transitioning from " + oldPolicy + " to " + policy);
}
if (!isInteractivePolicy(policy) && isInteractivePolicy(oldPolicy)) {
@@ -380,7 +317,7 @@
mBrightnessMapper.addUserDataPoint(mAmbientLux, brightness);
mShortTermModelValid = true;
mShortTermModelAnchor = mAmbientLux;
- if (mLoggingEnabled) {
+ if (DEBUG) {
Slog.d(TAG, "ShortTermModel: anchor=" + mShortTermModelAnchor);
}
return true;
@@ -393,7 +330,7 @@
}
private void invalidateShortTermModel() {
- if (mLoggingEnabled) {
+ if (DEBUG) {
Slog.d(TAG, "ShortTermModel: invalidate user data");
}
mShortTermModelValid = false;
@@ -446,11 +383,7 @@
pw.println(" mBrightnessAdjustmentSampleOldLux=" + mBrightnessAdjustmentSampleOldLux);
pw.println(" mBrightnessAdjustmentSampleOldBrightness="
+ mBrightnessAdjustmentSampleOldBrightness);
- pw.println(" mUserId=" + mUserId);
- pw.println(" mForegroundAppPackageName=" + mForegroundAppPackageName);
- pw.println(" mPendingForegroundAppPackageName=" + mPendingForegroundAppPackageName);
- pw.println(" mForegroundAppCategory=" + mForegroundAppCategory);
- pw.println(" mPendingForegroundAppCategory=" + mPendingForegroundAppCategory);
+ pw.println(" mShortTermModelValid=" + mShortTermModelValid);
pw.println();
mBrightnessMapper.dump(pw);
@@ -466,7 +399,6 @@
mLightSensorEnabled = true;
mLightSensorEnableTime = SystemClock.uptimeMillis();
mCurrentLightSensorRate = mInitialLightSensorRate;
- registerForegroundAppUpdater();
mSensorManager.registerListener(mLightSensorListener, mLightSensor,
mCurrentLightSensorRate * 1000, mHandler);
return true;
@@ -479,7 +411,6 @@
mAmbientLightRingBuffer.clear();
mCurrentLightSensorRate = -1;
mHandler.removeMessages(MSG_UPDATE_AMBIENT_LUX);
- unregisterForegroundAppUpdater();
mSensorManager.unregisterListener(mLightSensorListener);
}
return false;
@@ -510,7 +441,7 @@
private void adjustLightSensorRate(int lightSensorRate) {
// if the light sensor rate changed, update the sensor listener
if (lightSensorRate != mCurrentLightSensorRate) {
- if (mLoggingEnabled) {
+ if (DEBUG) {
Slog.d(TAG, "adjustLightSensorRate: " +
"previousRate=" + mCurrentLightSensorRate + ", " +
"currentRate=" + lightSensorRate);
@@ -527,7 +458,7 @@
}
private void setAmbientLux(float lux) {
- if (mLoggingEnabled) {
+ if (DEBUG) {
Slog.d(TAG, "setAmbientLux(" + lux + ")");
}
if (lux < 0) {
@@ -545,7 +476,7 @@
final float maxAmbientLux =
mShortTermModelAnchor + mShortTermModelAnchor * SHORT_TERM_MODEL_THRESHOLD_RATIO;
if (minAmbientLux < mAmbientLux && mAmbientLux < maxAmbientLux) {
- if (mLoggingEnabled) {
+ if (DEBUG) {
Slog.d(TAG, "ShortTermModel: re-validate user data, ambient lux is " +
minAmbientLux + " < " + mAmbientLux + " < " + maxAmbientLux);
}
@@ -559,7 +490,7 @@
}
private float calculateAmbientLux(long now, long horizon) {
- if (mLoggingEnabled) {
+ if (DEBUG) {
Slog.d(TAG, "calculateAmbientLux(" + now + ", " + horizon + ")");
}
final int N = mAmbientLightRingBuffer.size();
@@ -578,7 +509,7 @@
break;
}
}
- if (mLoggingEnabled) {
+ if (DEBUG) {
Slog.d(TAG, "calculateAmbientLux: selected endIndex=" + endIndex + ", point=(" +
mAmbientLightRingBuffer.getTime(endIndex) + ", " +
mAmbientLightRingBuffer.getLux(endIndex) + ")");
@@ -596,7 +527,7 @@
final long startTime = eventTime - now;
float weight = calculateWeight(startTime, endTime);
float lux = mAmbientLightRingBuffer.getLux(i);
- if (mLoggingEnabled) {
+ if (DEBUG) {
Slog.d(TAG, "calculateAmbientLux: [" + startTime + ", " + endTime + "]: " +
"lux=" + lux + ", " +
"weight=" + weight);
@@ -605,7 +536,7 @@
sum += lux * weight;
endTime = startTime;
}
- if (mLoggingEnabled) {
+ if (DEBUG) {
Slog.d(TAG, "calculateAmbientLux: " +
"totalWeight=" + totalWeight + ", " +
"newAmbientLux=" + (sum / totalWeight));
@@ -660,7 +591,7 @@
final long timeWhenSensorWarmedUp =
mLightSensorWarmUpTimeConfig + mLightSensorEnableTime;
if (time < timeWhenSensorWarmedUp) {
- if (mLoggingEnabled) {
+ if (DEBUG) {
Slog.d(TAG, "updateAmbientLux: Sensor not ready yet: " +
"time=" + time + ", " +
"timeWhenSensorWarmedUp=" + timeWhenSensorWarmedUp);
@@ -671,7 +602,7 @@
}
setAmbientLux(calculateAmbientLux(time, AMBIENT_LIGHT_SHORT_HORIZON_MILLIS));
mAmbientLuxValid = true;
- if (mLoggingEnabled) {
+ if (DEBUG) {
Slog.d(TAG, "updateAmbientLux: Initializing: " +
"mAmbientLightRingBuffer=" + mAmbientLightRingBuffer + ", " +
"mAmbientLux=" + mAmbientLux);
@@ -699,10 +630,10 @@
&& fastAmbientLux <= mAmbientDarkeningThreshold
&& nextDarkenTransition <= time)) {
setAmbientLux(fastAmbientLux);
- if (mLoggingEnabled) {
+ if (DEBUG) {
Slog.d(TAG, "updateAmbientLux: "
+ ((fastAmbientLux > mAmbientLux) ? "Brightened" : "Darkened") + ": "
- + "mBrighteningLuxThreshold=" + mAmbientBrighteningThreshold + ", "
+ + "mAmbientBrighteningThreshold=" + mAmbientBrighteningThreshold + ", "
+ "mAmbientLightRingBuffer=" + mAmbientLightRingBuffer + ", "
+ "mAmbientLux=" + mAmbientLux);
}
@@ -719,7 +650,7 @@
// weighted ambient lux or not.
nextTransitionTime =
nextTransitionTime > time ? nextTransitionTime : time + mNormalLightSensorRate;
- if (mLoggingEnabled) {
+ if (DEBUG) {
Slog.d(TAG, "updateAmbientLux: Scheduling ambient lux update for " +
nextTransitionTime + TimeUtils.formatUptime(nextTransitionTime));
}
@@ -731,8 +662,7 @@
return;
}
- float value = mBrightnessMapper.getBrightness(mAmbientLux, mForegroundAppPackageName,
- mForegroundAppCategory);
+ float value = mBrightnessMapper.getBrightness(mAmbientLux);
int newScreenAutoBrightness =
clampScreenBrightness(Math.round(value * PowerManager.BRIGHTNESS_ON));
@@ -743,7 +673,7 @@
if (mScreenAutoBrightness != -1
&& newScreenAutoBrightness > mScreenDarkeningThreshold
&& newScreenAutoBrightness < mScreenBrighteningThreshold) {
- if (mLoggingEnabled) {
+ if (DEBUG) {
Slog.d(TAG, "ignoring newScreenAutoBrightness: " + mScreenDarkeningThreshold
+ " < " + newScreenAutoBrightness + " < " + mScreenBrighteningThreshold);
}
@@ -751,7 +681,8 @@
}
if (mScreenAutoBrightness != newScreenAutoBrightness) {
- if (mLoggingEnabled) {
+
+ if (DEBUG) {
Slog.d(TAG, "updateAutoBrightness: " +
"mScreenAutoBrightness=" + mScreenAutoBrightness + ", " +
"newScreenAutoBrightness=" + newScreenAutoBrightness);
@@ -787,11 +718,18 @@
BRIGHTNESS_ADJUSTMENT_SAMPLE_DEBOUNCE_MILLIS);
}
+ private void cancelBrightnessAdjustmentSample() {
+ if (mBrightnessAdjustmentSamplePending) {
+ mBrightnessAdjustmentSamplePending = false;
+ mHandler.removeMessages(MSG_BRIGHTNESS_ADJUSTMENT_SAMPLE);
+ }
+ }
+
private void collectBrightnessAdjustmentSample() {
if (mBrightnessAdjustmentSamplePending) {
mBrightnessAdjustmentSamplePending = false;
if (mAmbientLuxValid && mScreenAutoBrightness >= 0) {
- if (mLoggingEnabled) {
+ if (DEBUG) {
Slog.d(TAG, "Auto-brightness adjustment changed by user: " +
"lux=" + mAmbientLux + ", " +
"brightness=" + mScreenAutoBrightness + ", " +
@@ -807,68 +745,6 @@
}
}
- // Register a TaskStackListener to call back to us onTaskStackChanged, so we can update the
- // foreground app's package name and category and correct the brightness accordingly.
- private void registerForegroundAppUpdater() {
- try {
- mActivityTaskManager.registerTaskStackListener(mTaskStackListener);
- // This will not get called until the foreground app changes for the first time, so
- // call it explicitly to get the current foreground app's info.
- updateForegroundApp();
- } catch (RemoteException e) {
- // Nothing to do.
- }
- }
-
- private void unregisterForegroundAppUpdater() {
- try {
- mActivityTaskManager.unregisterTaskStackListener(mTaskStackListener);
- } catch (RemoteException e) {
- // Nothing to do.
- }
- mForegroundAppPackageName = null;
- mForegroundAppCategory = ApplicationInfo.CATEGORY_UNDEFINED;
- }
-
- // Set the foreground app's package name and category, so brightness can be corrected per app.
- private void updateForegroundApp() {
- // The ActivityTaskManager's lock tends to get contended, so this is done in a background
- // thread and applied via this thread's handler synchronously.
- BackgroundThread.getHandler().post(new Runnable() {
- public void run() {
- try {
- // The foreground app is the top activity of the focused tasks stack.
- final StackInfo info = mActivityTaskManager.getFocusedStackInfo();
- if (info == null || info.topActivity == null) {
- return;
- }
- final String packageName = info.topActivity.getPackageName();
- // If the app didn't change, there's nothing to do. Otherwise, we have to
- // update the category and re-apply the brightness correction.
- if (mForegroundAppPackageName != null
- && mForegroundAppPackageName.equals(packageName)) {
- return;
- }
- mPendingForegroundAppPackageName = packageName;
- ApplicationInfo app = mPackageManagerInternal.getApplicationInfo(packageName,
- 0 /* flags */, Process.SYSTEM_UID /* filterCallingUid */, mUserId);
- mPendingForegroundAppCategory = app.category;
- mHandler.sendEmptyMessage(MSG_UPDATE_FOREGROUND_APP_SYNC);
- } catch (RemoteException e) {
- // Nothing to do.
- }
- }
- });
- }
-
- private void updateForegroundAppSync() {
- mForegroundAppPackageName = mPendingForegroundAppPackageName;
- mPendingForegroundAppPackageName = null;
- mForegroundAppCategory = mPendingForegroundAppCategory;
- mPendingForegroundAppCategory = ApplicationInfo.CATEGORY_UNDEFINED;
- updateAutoBrightness(true /* sendUpdate */);
- }
-
private final class AutomaticBrightnessHandler extends Handler {
public AutomaticBrightnessHandler(Looper looper) {
super(looper, null, true /*async*/);
@@ -888,14 +764,6 @@
case MSG_INVALIDATE_SHORT_TERM_MODEL:
invalidateShortTermModel();
break;
-
- case MSG_UPDATE_FOREGROUND_APP:
- updateForegroundApp();
- break;
-
- case MSG_UPDATE_FOREGROUND_APP_SYNC:
- updateForegroundAppSync();
- break;
}
}
}
@@ -916,15 +784,6 @@
}
};
- // Call back whenever the tasks stack changes, which includes tasks being created, removed, and
- // moving to top.
- class TaskStackListenerImpl extends TaskStackListener {
- @Override
- public void onTaskStackChanged() {
- mHandler.sendEmptyMessage(MSG_UPDATE_FOREGROUND_APP);
- }
- }
-
/** Callbacks to request updates to the display's power state. */
interface Callbacks {
void updateBrightness();
diff --git a/services/core/java/com/android/server/display/BrightnessMappingStrategy.java b/services/core/java/com/android/server/display/BrightnessMappingStrategy.java
index 9fce644..76c191d 100644
--- a/services/core/java/com/android/server/display/BrightnessMappingStrategy.java
+++ b/services/core/java/com/android/server/display/BrightnessMappingStrategy.java
@@ -17,11 +17,9 @@
package com.android.server.display;
import android.annotation.Nullable;
-import android.content.pm.ApplicationInfo;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.hardware.display.BrightnessConfiguration;
-import android.hardware.display.BrightnessCorrection;
import android.os.PowerManager;
import android.util.MathUtils;
import android.util.Pair;
@@ -44,12 +42,11 @@
*/
public abstract class BrightnessMappingStrategy {
private static final String TAG = "BrightnessMappingStrategy";
+ private static final boolean DEBUG = false;
private static final float LUX_GRAD_SMOOTHING = 0.25f;
private static final float MAX_GRAD = 1.0f;
- protected boolean mLoggingEnabled;
-
private static final Plog PLOG = Plog.createSystemPlog(TAG);
@Nullable
@@ -164,22 +161,6 @@
}
/**
- * Enable/disable logging.
- *
- * @param loggingEnabled
- * Whether logging should be on/off.
- *
- * @return Whether the method succeeded or not.
- */
- public boolean setLoggingEnabled(boolean loggingEnabled) {
- if (mLoggingEnabled == loggingEnabled) {
- return false;
- }
- mLoggingEnabled = loggingEnabled;
- return true;
- }
-
- /**
* Sets the {@link BrightnessConfiguration}.
*
* @param config The new configuration. If {@code null} is passed, the default configuration is
@@ -189,33 +170,15 @@
public abstract boolean setBrightnessConfiguration(@Nullable BrightnessConfiguration config);
/**
- * Returns the desired brightness of the display based on the current ambient lux, including
- * any context-related corrections.
+ * Returns the desired brightness of the display based on the current ambient lux.
*
* The returned brightness will be in the range [0, 1.0], where 1.0 is the display at max
* brightness and 0 is the display at minimum brightness.
*
* @param lux The current ambient brightness in lux.
- * @param packageName the foreground app package name.
- * @param category the foreground app package category.
* @return The desired brightness of the display normalized to the range [0, 1.0].
*/
- public abstract float getBrightness(float lux, String packageName,
- @ApplicationInfo.Category int category);
-
- /**
- * Returns the desired brightness of the display based on the current ambient lux.
- *
- * The returned brightness wil be in the range [0, 1.0], where 1.0 is the display at max
- * brightness and 0 is the display at minimum brightness.
- *
- * @param lux The current ambient brightness in lux.
- *
- * @return The desired brightness of the display normalized to the range [0, 1.0].
- */
- public float getBrightness(float lux) {
- return getBrightness(lux, null /* packageName */, ApplicationInfo.CATEGORY_UNDEFINED);
- }
+ public abstract float getBrightness(float lux);
/**
* Returns the current auto-brightness adjustment.
@@ -276,13 +239,13 @@
public abstract void dump(PrintWriter pw);
- protected float normalizeAbsoluteBrightness(int brightness) {
+ private static float normalizeAbsoluteBrightness(int brightness) {
brightness = MathUtils.constrain(brightness,
PowerManager.BRIGHTNESS_OFF, PowerManager.BRIGHTNESS_ON);
return (float) brightness / PowerManager.BRIGHTNESS_ON;
}
- private Pair<float[], float[]> insertControlPoint(
+ private static Pair<float[], float[]> insertControlPoint(
float[] luxLevels, float[] brightnessLevels, float lux, float brightness) {
final int idx = findInsertionPoint(luxLevels, lux);
final float[] newLuxLevels;
@@ -315,7 +278,7 @@
* This assumes that {@code arr} is sorted. If all values in {@code arr} are greater
* than val, then it will return the length of arr as the insertion point.
*/
- private int findInsertionPoint(float[] arr, float val) {
+ private static int findInsertionPoint(float[] arr, float val) {
for (int i = 0; i < arr.length; i++) {
if (val <= arr[i]) {
return i;
@@ -324,8 +287,8 @@
return arr.length;
}
- private void smoothCurve(float[] lux, float[] brightness, int idx) {
- if (mLoggingEnabled) {
+ private static void smoothCurve(float[] lux, float[] brightness, int idx) {
+ if (DEBUG) {
PLOG.logCurve("unsmoothed curve", lux, brightness);
}
float prevLux = lux[idx];
@@ -360,19 +323,19 @@
prevBrightness = newBrightness;
brightness[i] = newBrightness;
}
- if (mLoggingEnabled) {
+ if (DEBUG) {
PLOG.logCurve("smoothed curve", lux, brightness);
}
}
- private float permissibleRatio(float currLux, float prevLux) {
+ private static float permissibleRatio(float currLux, float prevLux) {
return MathUtils.exp(MAX_GRAD
* (MathUtils.log(currLux + LUX_GRAD_SMOOTHING)
- MathUtils.log(prevLux + LUX_GRAD_SMOOTHING)));
}
- protected float inferAutoBrightnessAdjustment(float maxGamma, float desiredBrightness,
- float currentBrightness) {
+ private static float inferAutoBrightnessAdjustment(float maxGamma,
+ float desiredBrightness, float currentBrightness) {
float adjustment = 0;
float gamma = Float.NaN;
// Extreme edge cases: use a simpler heuristic, as proper gamma correction around the edges
@@ -392,7 +355,7 @@
adjustment = -MathUtils.log(gamma) / MathUtils.log(maxGamma);
}
adjustment = MathUtils.constrain(adjustment, -1, +1);
- if (mLoggingEnabled) {
+ if (DEBUG) {
Slog.d(TAG, "inferAutoBrightnessAdjustment: " + maxGamma + "^" + -adjustment + "=" +
MathUtils.pow(maxGamma, -adjustment) + " == " + gamma);
Slog.d(TAG, "inferAutoBrightnessAdjustment: " + currentBrightness + "^" + gamma + "=" +
@@ -401,16 +364,16 @@
return adjustment;
}
- protected Pair<float[], float[]> getAdjustedCurve(float[] lux, float[] brightness,
+ private static Pair<float[], float[]> getAdjustedCurve(float[] lux, float[] brightness,
float userLux, float userBrightness, float adjustment, float maxGamma) {
float[] newLux = lux;
float[] newBrightness = Arrays.copyOf(brightness, brightness.length);
- if (mLoggingEnabled) {
+ if (DEBUG) {
PLOG.logCurve("unadjusted curve", newLux, newBrightness);
}
adjustment = MathUtils.constrain(adjustment, -1, 1);
float gamma = MathUtils.pow(maxGamma, -adjustment);
- if (mLoggingEnabled) {
+ if (DEBUG) {
Slog.d(TAG, "getAdjustedCurve: " + maxGamma + "^" + -adjustment + "=" +
MathUtils.pow(maxGamma, -adjustment) + " == " + gamma);
}
@@ -419,7 +382,7 @@
newBrightness[i] = MathUtils.pow(newBrightness[i], gamma);
}
}
- if (mLoggingEnabled) {
+ if (DEBUG) {
PLOG.logCurve("gamma adjusted curve", newLux, newBrightness);
}
if (userLux != -1) {
@@ -427,7 +390,7 @@
userBrightness);
newLux = curve.first;
newBrightness = curve.second;
- if (mLoggingEnabled) {
+ if (DEBUG) {
PLOG.logCurve("gamma and user adjusted curve", newLux, newBrightness);
// This is done for comparison.
curve = insertControlPoint(lux, brightness, userLux, userBrightness);
@@ -477,7 +440,7 @@
mAutoBrightnessAdjustment = 0;
mUserLux = -1;
mUserBrightness = -1;
- if (mLoggingEnabled) {
+ if (DEBUG) {
PLOG.start("simple mapping strategy");
}
computeSpline();
@@ -489,8 +452,7 @@
}
@Override
- public float getBrightness(float lux, String packageName,
- @ApplicationInfo.Category int category) {
+ public float getBrightness(float lux) {
return mSpline.interpolate(lux);
}
@@ -505,7 +467,7 @@
if (adjustment == mAutoBrightnessAdjustment) {
return false;
}
- if (mLoggingEnabled) {
+ if (DEBUG) {
Slog.d(TAG, "setAutoBrightnessAdjustment: " + mAutoBrightnessAdjustment + " => " +
adjustment);
PLOG.start("auto-brightness adjustment");
@@ -523,7 +485,7 @@
@Override
public void addUserDataPoint(float lux, float brightness) {
float unadjustedBrightness = getUnadjustedBrightness(lux);
- if (mLoggingEnabled) {
+ if (DEBUG){
Slog.d(TAG, "addUserDataPoint: (" + lux + "," + brightness + ")");
PLOG.start("add user data point")
.logPoint("user data point", lux, brightness)
@@ -532,7 +494,7 @@
float adjustment = inferAutoBrightnessAdjustment(mMaxGamma,
brightness /* desiredBrightness */,
unadjustedBrightness /* currentBrightness */);
- if (mLoggingEnabled) {
+ if (DEBUG) {
Slog.d(TAG, "addUserDataPoint: " + mAutoBrightnessAdjustment + " => " +
adjustment);
}
@@ -545,7 +507,7 @@
@Override
public void clearUserDataPoints() {
if (mUserLux != -1) {
- if (mLoggingEnabled) {
+ if (DEBUG) {
Slog.d(TAG, "clearUserDataPoints: " + mAutoBrightnessAdjustment + " => 0");
PLOG.start("clear user data points")
.logPoint("user data point", mUserLux, mUserBrightness);
@@ -652,7 +614,7 @@
mBacklightToNitsSpline = Spline.createSpline(normalizedBacklight, nits);
mDefaultConfig = config;
- if (mLoggingEnabled) {
+ if (DEBUG) {
PLOG.start("physical mapping strategy");
}
mConfig = config;
@@ -667,7 +629,7 @@
if (config.equals(mConfig)) {
return false;
}
- if (mLoggingEnabled) {
+ if (DEBUG) {
PLOG.start("brightness configuration");
}
mConfig = config;
@@ -676,17 +638,9 @@
}
@Override
- public float getBrightness(float lux, String packageName,
- @ApplicationInfo.Category int category) {
+ public float getBrightness(float lux) {
float nits = mBrightnessSpline.interpolate(lux);
float backlight = mNitsToBacklightSpline.interpolate(nits);
- // Correct the brightness according to the current application and its category, but
- // only if no user data point is set (as this will oevrride the user setting).
- if (mUserLux == -1) {
- backlight = correctBrightness(backlight, packageName, category);
- } else if (mLoggingEnabled) {
- Slog.d(TAG, "user point set, correction not applied");
- }
return backlight;
}
@@ -701,7 +655,7 @@
if (adjustment == mAutoBrightnessAdjustment) {
return false;
}
- if (mLoggingEnabled) {
+ if (DEBUG) {
Slog.d(TAG, "setAutoBrightnessAdjustment: " + mAutoBrightnessAdjustment + " => " +
adjustment);
PLOG.start("auto-brightness adjustment");
@@ -719,7 +673,7 @@
@Override
public void addUserDataPoint(float lux, float brightness) {
float unadjustedBrightness = getUnadjustedBrightness(lux);
- if (mLoggingEnabled) {
+ if (DEBUG){
Slog.d(TAG, "addUserDataPoint: (" + lux + "," + brightness + ")");
PLOG.start("add user data point")
.logPoint("user data point", lux, brightness)
@@ -728,7 +682,7 @@
float adjustment = inferAutoBrightnessAdjustment(mMaxGamma,
brightness /* desiredBrightness */,
unadjustedBrightness /* currentBrightness */);
- if (mLoggingEnabled) {
+ if (DEBUG) {
Slog.d(TAG, "addUserDataPoint: " + mAutoBrightnessAdjustment + " => " +
adjustment);
}
@@ -741,7 +695,7 @@
@Override
public void clearUserDataPoints() {
if (mUserLux != -1) {
- if (mLoggingEnabled) {
+ if (DEBUG) {
Slog.d(TAG, "clearUserDataPoints: " + mAutoBrightnessAdjustment + " => 0");
PLOG.start("clear user data points")
.logPoint("user data point", mUserLux, mUserBrightness);
@@ -804,21 +758,5 @@
Spline spline = Spline.createSpline(curve.first, curve.second);
return mNitsToBacklightSpline.interpolate(spline.interpolate(lux));
}
-
- private float correctBrightness(float brightness, String packageName, int category) {
- if (packageName != null) {
- BrightnessCorrection correction = mConfig.getCorrectionByPackageName(packageName);
- if (correction != null) {
- return correction.apply(brightness);
- }
- }
- if (category != ApplicationInfo.CATEGORY_UNDEFINED) {
- BrightnessCorrection correction = mConfig.getCorrectionByCategory(category);
- if (correction != null) {
- return correction.apply(brightness);
- }
- }
- return brightness;
- }
}
}
diff --git a/services/core/java/com/android/server/display/DisplayManagerService.java b/services/core/java/com/android/server/display/DisplayManagerService.java
index b1ba05c..0a1a9a2 100644
--- a/services/core/java/com/android/server/display/DisplayManagerService.java
+++ b/services/core/java/com/android/server/display/DisplayManagerService.java
@@ -2144,14 +2144,6 @@
mContext.getPackageName());
}
- void setAutoBrightnessLoggingEnabled(boolean enabled) {
- if (mDisplayPowerController != null) {
- synchronized (mSyncRoot) {
- mDisplayPowerController.setAutoBrightnessLoggingEnabled(enabled);
- }
- }
- }
-
private boolean validatePackageName(int uid, String packageName) {
if (packageName != null) {
String[] packageNames = mContext.getPackageManager().getPackagesForUid(uid);
diff --git a/services/core/java/com/android/server/display/DisplayManagerShellCommand.java b/services/core/java/com/android/server/display/DisplayManagerShellCommand.java
index abbfc7b..27cad1e 100644
--- a/services/core/java/com/android/server/display/DisplayManagerShellCommand.java
+++ b/services/core/java/com/android/server/display/DisplayManagerShellCommand.java
@@ -17,9 +17,14 @@
package com.android.server.display;
import android.content.Intent;
+import android.os.RemoteException;
+import android.os.ResultReceiver;
+import android.os.ShellCallback;
import android.os.ShellCommand;
+import android.util.Slog;
import java.io.PrintWriter;
+import java.lang.NumberFormatException;
class DisplayManagerShellCommand extends ShellCommand {
private static final String TAG = "DisplayManagerShellCommand";
@@ -41,10 +46,6 @@
return setBrightness();
case "reset-brightness-configuration":
return resetBrightnessConfiguration();
- case "ab-logging-enable":
- return setAutoBrightnessLoggingEnabled(true);
- case "ab-logging-disable":
- return setAutoBrightnessLoggingEnabled(false);
default:
return handleDefaultCommands(cmd);
}
@@ -61,10 +62,6 @@
pw.println(" Sets the current brightness to BRIGHTNESS (a number between 0 and 1).");
pw.println(" reset-brightness-configuration");
pw.println(" Reset the brightness to its default configuration.");
- pw.println(" ab-logging-enable");
- pw.println(" Enable auto-brightness logging.");
- pw.println(" ab-logging-disable");
- pw.println(" Disable auto-brightness logging.");
pw.println();
Intent.printIntentArgsHelp(pw , "");
}
@@ -92,9 +89,4 @@
mService.resetBrightnessConfiguration();
return 0;
}
-
- private int setAutoBrightnessLoggingEnabled(boolean enabled) {
- mService.setAutoBrightnessLoggingEnabled(enabled);
- return 0;
- }
}
diff --git a/services/core/java/com/android/server/display/DisplayPowerController.java b/services/core/java/com/android/server/display/DisplayPowerController.java
index c9ed9f7..249270b 100644
--- a/services/core/java/com/android/server/display/DisplayPowerController.java
+++ b/services/core/java/com/android/server/display/DisplayPowerController.java
@@ -523,9 +523,6 @@
public void onSwitchUser(@UserIdInt int newUserId) {
handleSettingsChange(true /* userSwitch */);
mBrightnessTracker.onSwitchUser(newUserId);
- if (mAutomaticBrightnessController != null) {
- mAutomaticBrightnessController.onSwitchUser(newUserId);
- }
}
public ParceledListSlice<AmbientBrightnessDayStats> getAmbientBrightnessStats(
@@ -1839,10 +1836,4 @@
mHandler.sendMessage(msg);
}
}
-
- void setAutoBrightnessLoggingEnabled(boolean enabled) {
- if (mAutomaticBrightnessController != null) {
- mAutomaticBrightnessController.setLoggingEnabled(enabled);
- }
- }
}
diff --git a/services/core/java/com/android/server/display/PersistentDataStore.java b/services/core/java/com/android/server/display/PersistentDataStore.java
index 9aec43b..89cef62 100644
--- a/services/core/java/com/android/server/display/PersistentDataStore.java
+++ b/services/core/java/com/android/server/display/PersistentDataStore.java
@@ -16,6 +16,13 @@
package com.android.server.display;
+import com.android.internal.util.FastXmlSerializer;
+import com.android.internal.util.XmlUtils;
+
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+import org.xmlpull.v1.XmlSerializer;
+
import android.annotation.Nullable;
import android.graphics.Point;
import android.hardware.display.BrightnessConfiguration;
@@ -23,20 +30,13 @@
import android.util.AtomicFile;
import android.util.Slog;
import android.util.SparseArray;
+import android.util.Pair;
import android.util.SparseLongArray;
import android.util.TimeUtils;
import android.util.Xml;
import android.view.Display;
import com.android.internal.annotations.VisibleForTesting;
-import com.android.internal.util.FastXmlSerializer;
-import com.android.internal.util.XmlUtils;
-
-import libcore.io.IoUtils;
-
-import org.xmlpull.v1.XmlPullParser;
-import org.xmlpull.v1.XmlPullParserException;
-import org.xmlpull.v1.XmlSerializer;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
@@ -50,9 +50,12 @@
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.Objects;
+import libcore.io.IoUtils;
+
/**
* Manages persistent state recorded by the display manager service as an XML file.
* Caller must acquire lock on the data store before accessing it.
@@ -107,9 +110,14 @@
private static final String TAG_BRIGHTNESS_CONFIGURATIONS = "brightness-configurations";
private static final String TAG_BRIGHTNESS_CONFIGURATION = "brightness-configuration";
+ private static final String TAG_BRIGHTNESS_CURVE = "brightness-curve";
+ private static final String TAG_BRIGHTNESS_POINT = "brightness-point";
private static final String ATTR_USER_SERIAL = "user-serial";
private static final String ATTR_PACKAGE_NAME = "package-name";
private static final String ATTR_TIME_STAMP = "timestamp";
+ private static final String ATTR_LUX = "lux";
+ private static final String ATTR_NITS = "nits";
+ private static final String ATTR_DESCRIPTION = "description";
// Remembered Wifi display devices.
private ArrayList<WifiDisplay> mRememberedWifiDisplays = new ArrayList<WifiDisplay>();
@@ -638,8 +646,7 @@
}
try {
- BrightnessConfiguration config =
- BrightnessConfiguration.loadFromXml(parser);
+ BrightnessConfiguration config = loadConfigurationFromXml(parser);
if (userSerial >= 0 && config != null) {
mConfigurations.put(userSerial, config);
if (timeStamp != -1) {
@@ -656,6 +663,56 @@
}
}
+ private static BrightnessConfiguration loadConfigurationFromXml(XmlPullParser parser)
+ throws IOException, XmlPullParserException {
+ final int outerDepth = parser.getDepth();
+ String description = null;
+ Pair<float[], float[]> curve = null;
+ while (XmlUtils.nextElementWithin(parser, outerDepth)) {
+ if (TAG_BRIGHTNESS_CURVE.equals(parser.getName())) {
+ description = parser.getAttributeValue(null, ATTR_DESCRIPTION);
+ curve = loadCurveFromXml(parser);
+ }
+ }
+ if (curve == null) {
+ return null;
+ }
+ final BrightnessConfiguration.Builder builder = new BrightnessConfiguration.Builder(
+ curve.first, curve.second);
+ builder.setDescription(description);
+ return builder.build();
+ }
+
+ private static Pair<float[], float[]> loadCurveFromXml(XmlPullParser parser)
+ throws IOException, XmlPullParserException {
+ final int outerDepth = parser.getDepth();
+ List<Float> luxLevels = new ArrayList<>();
+ List<Float> nitLevels = new ArrayList<>();
+ while (XmlUtils.nextElementWithin(parser, outerDepth)) {
+ if (TAG_BRIGHTNESS_POINT.equals(parser.getName())) {
+ luxLevels.add(loadFloat(parser.getAttributeValue(null, ATTR_LUX)));
+ nitLevels.add(loadFloat(parser.getAttributeValue(null, ATTR_NITS)));
+ }
+ }
+ final int N = luxLevels.size();
+ float[] lux = new float[N];
+ float[] nits = new float[N];
+ for (int i = 0; i < N; i++) {
+ lux[i] = luxLevels.get(i);
+ nits[i] = nitLevels.get(i);
+ }
+ return Pair.create(lux, nits);
+ }
+
+ private static float loadFloat(String val) {
+ try {
+ return Float.parseFloat(val);
+ } catch (NullPointerException | NumberFormatException e) {
+ Slog.e(TAG, "Failed to parse float loading brightness config", e);
+ return Float.NEGATIVE_INFINITY;
+ }
+ }
+
public void saveToXml(XmlSerializer serializer) throws IOException {
for (int i = 0; i < mConfigurations.size(); i++) {
final int userSerial = mConfigurations.keyAt(i);
@@ -671,11 +728,27 @@
if (timestamp != -1) {
serializer.attribute(null, ATTR_TIME_STAMP, Long.toString(timestamp));
}
- config.saveToXml(serializer);
+ saveConfigurationToXml(serializer, config);
serializer.endTag(null, TAG_BRIGHTNESS_CONFIGURATION);
}
}
+ private static void saveConfigurationToXml(XmlSerializer serializer,
+ BrightnessConfiguration config) throws IOException {
+ serializer.startTag(null, TAG_BRIGHTNESS_CURVE);
+ if (config.getDescription() != null) {
+ serializer.attribute(null, ATTR_DESCRIPTION, config.getDescription());
+ }
+ final Pair<float[], float[]> curve = config.getCurve();
+ for (int i = 0; i < curve.first.length; i++) {
+ serializer.startTag(null, TAG_BRIGHTNESS_POINT);
+ serializer.attribute(null, ATTR_LUX, Float.toString(curve.first[i]));
+ serializer.attribute(null, ATTR_NITS, Float.toString(curve.second[i]));
+ serializer.endTag(null, TAG_BRIGHTNESS_POINT);
+ }
+ serializer.endTag(null, TAG_BRIGHTNESS_CURVE);
+ }
+
public void dump(final PrintWriter pw, final String prefix) {
for (int i = 0; i < mConfigurations.size(); i++) {
final int userSerial = mConfigurations.keyAt(i);
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java
index 25ec3c4..c2c8825 100644
--- a/services/core/java/com/android/server/notification/NotificationManagerService.java
+++ b/services/core/java/com/android/server/notification/NotificationManagerService.java
@@ -1316,6 +1316,11 @@
}
@VisibleForTesting
+ void setHints(int hints) {
+ mListenerHints = hints;
+ }
+
+ @VisibleForTesting
void setVibrator(Vibrator vibrator) {
mVibrator = vibrator;
}
@@ -3992,6 +3997,20 @@
if ((mListenerHints & HINT_HOST_DISABLE_EFFECTS) != 0) {
return "listenerHints";
}
+ if (record != null && record.getAudioAttributes() != null) {
+ if ((mListenerHints & HINT_HOST_DISABLE_NOTIFICATION_EFFECTS) != 0) {
+ if (record.getAudioAttributes().getUsage()
+ != AudioAttributes.USAGE_VOICE_COMMUNICATION) {
+ return "listenerNoti";
+ }
+ }
+ if ((mListenerHints & HINT_HOST_DISABLE_CALL_EFFECTS) != 0) {
+ if (record.getAudioAttributes().getUsage()
+ == AudioAttributes.USAGE_VOICE_COMMUNICATION) {
+ return "listenerCall";
+ }
+ }
+ }
if (mCallState != TelephonyManager.CALL_STATE_IDLE && !mZenModeHelper.isCall(record)) {
return "callState";
}
diff --git a/services/core/java/com/android/server/pm/PackageInstallerSession.java b/services/core/java/com/android/server/pm/PackageInstallerSession.java
index 795f655..982daa5 100644
--- a/services/core/java/com/android/server/pm/PackageInstallerSession.java
+++ b/services/core/java/com/android/server/pm/PackageInstallerSession.java
@@ -17,6 +17,7 @@
package com.android.server.pm;
import static android.content.pm.PackageManager.INSTALL_FAILED_ABORTED;
+import static android.content.pm.PackageManager.INSTALL_FAILED_BAD_SIGNATURE;
import static android.content.pm.PackageManager.INSTALL_FAILED_CONTAINER_ERROR;
import static android.content.pm.PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE;
import static android.content.pm.PackageManager.INSTALL_FAILED_INTERNAL_ERROR;
@@ -106,6 +107,7 @@
import com.android.server.pm.Installer.InstallerException;
import com.android.server.pm.PackageInstallerService.PackageInstallObserverAdapter;
import com.android.server.pm.dex.DexManager;
+import com.android.server.security.VerityUtils;
import libcore.io.IoUtils;
@@ -285,6 +287,8 @@
private final List<String> mResolvedNativeLibPaths = new ArrayList<>();
@GuardedBy("mLock")
private File mInheritedFilesBase;
+ @GuardedBy("mLock")
+ private boolean mVerityFound;
private static final FileFilter sAddedFilter = new FileFilter() {
@Override
@@ -294,6 +298,7 @@
if (file.isDirectory()) return false;
if (file.getName().endsWith(REMOVE_SPLIT_MARKER_EXTENSION)) return false;
if (DexMetadataHelper.isDexMetadataFile(file)) return false;
+ if (VerityUtils.isFsveritySignatureFile(file)) return false;
return true;
}
};
@@ -1362,6 +1367,16 @@
mResolvedStagedFiles.clear();
mResolvedInheritedFiles.clear();
+ // Partial installs must be consistent with existing install
+ if (params.mode == SessionParams.MODE_INHERIT_EXISTING
+ && (pkgInfo == null || pkgInfo.applicationInfo == null)) {
+ throw new PackageManagerException(INSTALL_FAILED_INVALID_APK,
+ "Missing existing base package");
+ }
+ // Default to require only if existing base has fs-verity.
+ mVerityFound = params.mode == SessionParams.MODE_INHERIT_EXISTING
+ && VerityUtils.hasFsverity(pkgInfo.applicationInfo.getBaseCodePath());
+
try {
resolveStageDirLocked();
} catch (IOException e) {
@@ -1425,7 +1440,7 @@
}
final File targetFile = new File(mResolvedStageDir, targetName);
- maybeRenameFile(addedFile, targetFile);
+ resolveAndStageFile(addedFile, targetFile);
// Base is coming from session
if (apk.splitName == null) {
@@ -1433,8 +1448,6 @@
baseApk = apk;
}
- mResolvedStagedFiles.add(targetFile);
-
final File dexMetadataFile = DexMetadataHelper.findDexMetadataForFile(addedFile);
if (dexMetadataFile != null) {
if (!FileUtils.isValidExtFilename(dexMetadataFile.getName())) {
@@ -1443,8 +1456,7 @@
}
final File targetDexMetadataFile = new File(mResolvedStageDir,
DexMetadataHelper.buildDexMetadataPathForApk(targetName));
- mResolvedStagedFiles.add(targetDexMetadataFile);
- maybeRenameFile(dexMetadataFile, targetDexMetadataFile);
+ resolveAndStageFile(dexMetadataFile, targetDexMetadataFile);
}
}
@@ -1487,12 +1499,6 @@
}
} else {
- // Partial installs must be consistent with existing install
- if (pkgInfo == null || pkgInfo.applicationInfo == null) {
- throw new PackageManagerException(INSTALL_FAILED_INVALID_APK,
- "Missing existing base package for " + mPackageName);
- }
-
final PackageLite existing;
final ApkLite existingBase;
ApplicationInfo appInfo = pkgInfo.applicationInfo;
@@ -1612,6 +1618,39 @@
}
}
+ private void resolveAndStageFile(File origFile, File targetFile)
+ throws PackageManagerException {
+ mResolvedStagedFiles.add(targetFile);
+ maybeRenameFile(origFile, targetFile);
+
+ final File originalSignature = new File(
+ VerityUtils.getFsveritySignatureFilePath(origFile.getPath()));
+ // Make sure .fsv_sig exists when it should, then resolve and stage it.
+ if (originalSignature.exists()) {
+ // mVerityFound can only change from false to true here during the staging loop. Since
+ // all or none of files should have .fsv_sig, this should only happen in the first time
+ // (or never), otherwise bail out.
+ if (!mVerityFound) {
+ mVerityFound = true;
+ if (mResolvedStagedFiles.size() > 1) {
+ throw new PackageManagerException(INSTALL_FAILED_BAD_SIGNATURE,
+ "Some file is missing fs-verity signature");
+ }
+ }
+ } else {
+ if (!mVerityFound) {
+ return;
+ }
+ throw new PackageManagerException(INSTALL_FAILED_BAD_SIGNATURE,
+ "Missing corresponding fs-verity signature to " + origFile);
+ }
+
+ final File stagedSignature = new File(
+ VerityUtils.getFsveritySignatureFilePath(targetFile.getPath()));
+ maybeRenameFile(originalSignature, stagedSignature);
+ mResolvedStagedFiles.add(stagedSignature);
+ }
+
@GuardedBy("mLock")
private void assertApkConsistentLocked(String tag, ApkLite apk)
throws PackageManagerException {
diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java
index 136c7c9..fe89be6 100644
--- a/services/core/java/com/android/server/pm/PackageManagerService.java
+++ b/services/core/java/com/android/server/pm/PackageManagerService.java
@@ -8549,16 +8549,16 @@
}
/**
- * Returns if full apk verification can be skipped for the whole package, including the splits.
+ * Returns if forced apk verification can be skipped for the whole package, including splits.
*/
- private boolean canSkipFullPackageVerification(PackageParser.Package pkg) {
- if (!canSkipFullApkVerification(pkg.baseCodePath)) {
+ private boolean canSkipForcedPackageVerification(PackageParser.Package pkg) {
+ if (!canSkipForcedApkVerification(pkg.baseCodePath)) {
return false;
}
// TODO: Allow base and splits to be verified individually.
if (!ArrayUtils.isEmpty(pkg.splitCodePaths)) {
for (int i = 0; i < pkg.splitCodePaths.length; i++) {
- if (!canSkipFullApkVerification(pkg.splitCodePaths[i])) {
+ if (!canSkipForcedApkVerification(pkg.splitCodePaths[i])) {
return false;
}
}
@@ -8567,14 +8567,17 @@
}
/**
- * Returns if full apk verification can be skipped, depending on current FSVerity setup and
+ * Returns if forced apk verification can be skipped, depending on current FSVerity setup and
* whether the apk contains signed root hash. Note that the signer's certificate still needs to
* match one in a trusted source, and should be done separately.
*/
- private boolean canSkipFullApkVerification(String apkPath) {
- final byte[] rootHashObserved;
+ private boolean canSkipForcedApkVerification(String apkPath) {
+ if (!PackageManagerServiceUtils.isLegacyApkVerityMode()) {
+ return VerityUtils.hasFsverity(apkPath);
+ }
+
try {
- rootHashObserved = VerityUtils.generateApkVerityRootHash(apkPath);
+ final byte[] rootHashObserved = VerityUtils.generateApkVerityRootHash(apkPath);
if (rootHashObserved == null) {
return false; // APK does not contain Merkle tree root hash.
}
@@ -8746,7 +8749,7 @@
// in verified partition, or can be verified on access (when apk verity is enabled). In both
// cases, only data in Signing Block is verified instead of the whole file.
final boolean skipVerify = scanSystemPartition
- || (forceCollect && canSkipFullPackageVerification(pkg));
+ || (forceCollect && canSkipForcedPackageVerification(pkg));
collectCertificatesLI(pkgSetting, pkg, forceCollect, skipVerify);
// Reset profile if the application version is changed
@@ -16552,44 +16555,11 @@
throw new PrepareFailure(INSTALL_FAILED_INSUFFICIENT_STORAGE, "Failed rename");
}
- if (PackageManagerServiceUtils.isApkVerityEnabled()) {
- String apkPath = null;
- synchronized (mPackages) {
- // Note that if the attacker managed to skip verify setup, for example by tampering
- // with the package settings, upon reboot we will do full apk verification when
- // verity is not detected.
- final PackageSetting ps = mSettings.mPackages.get(pkgName);
- if (ps != null && ps.isPrivileged()) {
- apkPath = pkg.baseCodePath;
- }
- }
- if (apkPath != null) {
- final VerityUtils.SetupResult result =
- VerityUtils.generateApkVeritySetupData(apkPath, null /* signaturePath */,
- true /* skipSigningBlock */);
- if (result.isOk()) {
- if (Build.IS_DEBUGGABLE) Slog.i(TAG, "Enabling apk verity to " + apkPath);
- FileDescriptor fd = result.getUnownedFileDescriptor();
- try {
- final byte[] signedRootHash =
- VerityUtils.generateApkVerityRootHash(apkPath);
- mInstaller.installApkVerity(apkPath, fd, result.getContentSize());
- mInstaller.assertFsverityRootHashMatches(apkPath, signedRootHash);
- } catch (InstallerException | IOException | DigestException |
- NoSuchAlgorithmException e) {
- throw new PrepareFailure(INSTALL_FAILED_INTERNAL_ERROR,
- "Failed to set up verity: " + e);
- } finally {
- IoUtils.closeQuietly(fd);
- }
- } else if (result.isFailed()) {
- throw new PrepareFailure(INSTALL_FAILED_INTERNAL_ERROR,
- "Failed to generate verity");
- } else {
- // Do nothing if verity is skipped. Will fall back to full apk verification on
- // reboot.
- }
- }
+ try {
+ setUpFsVerityIfPossible(pkg);
+ } catch (InstallerException | IOException | DigestException | NoSuchAlgorithmException e) {
+ throw new PrepareFailure(INSTALL_FAILED_INTERNAL_ERROR,
+ "Failed to set up verity: " + e);
}
if (!instantApp) {
@@ -16887,6 +16857,85 @@
}
}
+ /**
+ * Set up fs-verity for the given package if possible. This requires a feature flag of system
+ * property to be enabled only if the kernel supports fs-verity.
+ *
+ * <p>When the feature flag is set to legacy mode, only APK is supported (with some experimental
+ * kernel patches). In normal mode, all file format can be supported.
+ */
+ private void setUpFsVerityIfPossible(PackageParser.Package pkg) throws InstallerException,
+ PrepareFailure, IOException, DigestException, NoSuchAlgorithmException {
+ if (!PackageManagerServiceUtils.isApkVerityEnabled()) {
+ return;
+ }
+ final boolean legacyMode = PackageManagerServiceUtils.isLegacyApkVerityMode();
+
+ // Collect files we care for fs-verity setup.
+ ArrayMap<String, String> fsverityCandidates = new ArrayMap<>();
+ if (legacyMode) {
+ synchronized (mPackages) {
+ final PackageSetting ps = mSettings.mPackages.get(pkg.packageName);
+ if (ps != null && ps.isPrivileged()) {
+ fsverityCandidates.put(pkg.baseCodePath, null);
+ if (pkg.splitCodePaths != null) {
+ for (String splitPath : pkg.splitCodePaths) {
+ fsverityCandidates.put(splitPath, null);
+ }
+ }
+ }
+ }
+ } else {
+ // NB: These files will become only accessible if the signing key is loaded in kernel's
+ // .fs-verity keyring.
+ fsverityCandidates.put(pkg.baseCodePath,
+ VerityUtils.getFsveritySignatureFilePath(pkg.baseCodePath));
+
+ final String dmPath = DexMetadataHelper.buildDexMetadataPathForApk(pkg.baseCodePath);
+ if (new File(dmPath).exists()) {
+ fsverityCandidates.put(dmPath, VerityUtils.getFsveritySignatureFilePath(dmPath));
+ }
+
+ if (pkg.splitCodePaths != null) {
+ for (String path : pkg.splitCodePaths) {
+ fsverityCandidates.put(path, VerityUtils.getFsveritySignatureFilePath(path));
+
+ final String splitDmPath = DexMetadataHelper.buildDexMetadataPathForApk(path);
+ if (new File(splitDmPath).exists()) {
+ fsverityCandidates.put(splitDmPath,
+ VerityUtils.getFsveritySignatureFilePath(splitDmPath));
+ }
+ }
+ }
+ }
+
+ for (Map.Entry<String, String> entry : fsverityCandidates.entrySet()) {
+ final String filePath = entry.getKey();
+ final String signaturePath = entry.getValue();
+
+ final VerityUtils.SetupResult result = VerityUtils.generateApkVeritySetupData(
+ filePath, signaturePath, legacyMode);
+ if (result.isOk()) {
+ if (Build.IS_DEBUGGABLE) Slog.i(TAG, "Enabling verity to " + filePath);
+ final FileDescriptor fd = result.getUnownedFileDescriptor();
+ try {
+ mInstaller.installApkVerity(filePath, fd, result.getContentSize());
+
+ // In legacy mode, fs-verity can only be enabled by process with CAP_SYS_ADMIN.
+ if (legacyMode) {
+ final byte[] rootHash = VerityUtils.generateApkVerityRootHash(filePath);
+ mInstaller.assertFsverityRootHashMatches(filePath, rootHash);
+ }
+ } finally {
+ IoUtils.closeQuietly(fd);
+ }
+ } else if (result.isFailed()) {
+ throw new PrepareFailure(PackageManager.INSTALL_FAILED_BAD_SIGNATURE,
+ "Failed to generate verity");
+ }
+ }
+ }
+
private void startIntentFilterVerifications(int userId, boolean replacing,
PackageParser.Package pkg) {
if (mIntentFilterVerifierComponent == null) {
diff --git a/services/core/java/com/android/server/pm/PackageManagerServiceUtils.java b/services/core/java/com/android/server/pm/PackageManagerServiceUtils.java
index 36948fc..25169a2 100644
--- a/services/core/java/com/android/server/pm/PackageManagerServiceUtils.java
+++ b/services/core/java/com/android/server/pm/PackageManagerServiceUtils.java
@@ -543,9 +543,26 @@
}
}
+ /** Default is to not use fs-verity since it depends on kernel support. */
+ private static final int FSVERITY_DISABLED = 0;
+
+ /**
+ * Experimental implementation targeting priv apps, with Android specific kernel patches to
+ * extend fs-verity.
+ */
+ private static final int FSVERITY_LEGACY = 1;
+
+ /** Standard fs-verity. */
+ private static final int FSVERITY_ENABLED = 2;
+
/** Returns true if APK Verity is enabled. */
static boolean isApkVerityEnabled() {
- return SystemProperties.getInt("ro.apk_verity.mode", 0) != 0;
+ int mode = SystemProperties.getInt("ro.apk_verity.mode", FSVERITY_DISABLED);
+ return mode == FSVERITY_LEGACY || mode == FSVERITY_ENABLED;
+ }
+
+ static boolean isLegacyApkVerityMode() {
+ return SystemProperties.getInt("ro.apk_verity.mode", FSVERITY_DISABLED) == FSVERITY_LEGACY;
}
/** Returns true to force apk verification if the updated package (in /data) is a priv app. */
diff --git a/services/core/java/com/android/server/security/VerityUtils.java b/services/core/java/com/android/server/security/VerityUtils.java
index 667d21d..839ed30 100644
--- a/services/core/java/com/android/server/security/VerityUtils.java
+++ b/services/core/java/com/android/server/security/VerityUtils.java
@@ -30,6 +30,7 @@
import libcore.util.HexEncoding;
+import java.io.File;
import java.io.FileDescriptor;
import java.io.IOException;
import java.io.RandomAccessFile;
@@ -49,11 +50,27 @@
abstract public class VerityUtils {
private static final String TAG = "VerityUtils";
+ /**
+ * File extension of the signature file. For example, foo.apk.fsv_sig is the signature file of
+ * foo.apk.
+ */
+ public static final String FSVERITY_SIGNATURE_FILE_EXTENSION = ".fsv_sig";
+
/** The maximum size of signature file. This is just to avoid potential abuse. */
private static final int MAX_SIGNATURE_FILE_SIZE_BYTES = 8192;
private static final boolean DEBUG = false;
+ /** Returns true if the given file looks like containing an fs-verity signature. */
+ public static boolean isFsveritySignatureFile(File file) {
+ return file.getName().endsWith(FSVERITY_SIGNATURE_FILE_EXTENSION);
+ }
+
+ /** Returns the fs-verity signature file path of the given file. */
+ public static String getFsveritySignatureFilePath(String filePath) {
+ return filePath + FSVERITY_SIGNATURE_FILE_EXTENSION;
+ }
+
/** Returns whether the file has fs-verity enabled. */
public static boolean hasFsverity(@NonNull String filePath) {
// NB: only measure but not check the actual measurement here. As long as this succeeds,
diff --git a/services/core/java/com/android/server/wm/InsetsSourceProvider.java b/services/core/java/com/android/server/wm/InsetsSourceProvider.java
index 49a3186..fbb9e29 100644
--- a/services/core/java/com/android/server/wm/InsetsSourceProvider.java
+++ b/services/core/java/com/android/server/wm/InsetsSourceProvider.java
@@ -18,7 +18,6 @@
import android.annotation.NonNull;
import android.annotation.Nullable;
-import android.graphics.Point;
import android.graphics.Rect;
import android.util.proto.ProtoOutputStream;
import android.view.InsetsState;
@@ -28,6 +27,7 @@
import android.view.InsetsSourceControl;
import com.android.internal.util.function.TriConsumer;
+import com.android.internal.util.function.pooled.PooledLambda;
import com.android.server.wm.SurfaceAnimator.OnAnimationFinishedCallback;
import java.io.PrintWriter;
@@ -106,8 +106,8 @@
mTmpRect.inset(mWin.mGivenContentInsets);
}
mSource.setFrame(mTmpRect);
- setServerVisible(mWin.isVisible() && !mWin.mGivenInsetsPending);
-
+ setServerVisible(mWin.wouldBeVisibleIfPolicyIgnored() && mWin.mPolicyVisibility
+ && !mWin.mGivenInsetsPending);
}
void updateControlForTarget(@Nullable WindowState target) {
@@ -115,15 +115,15 @@
return;
}
if (target == null) {
- revokeControl();
+ // Cancelling the animation will invoke onAnimationCancelled, resetting all the fields.
+ mWin.cancelAnimation();
return;
}
mAdapter = new ControlAdapter();
mWin.startAnimation(mDisplayContent.getPendingTransaction(), mAdapter,
- false /* TODO hidden */);
+ !mClientVisible /* hidden */);
mControllingWin = target;
mControl = new InsetsSourceControl(mSource.getType(), mAdapter.mCapturedLeash);
- setClientVisible(InsetsState.getDefaultVisibly(mSource.getType()));
}
boolean onInsetsModified(WindowState caller, InsetsSource modifiedSource) {
@@ -135,7 +135,12 @@
}
private void setClientVisible(boolean clientVisible) {
+ if (mClientVisible == clientVisible) {
+ return;
+ }
mClientVisible = clientVisible;
+ mDisplayContent.mWmService.mH.sendMessage(PooledLambda.obtainMessage(
+ DisplayContent::layoutAndAssignWindowLayersIfNeeded, mDisplayContent));
updateVisibility();
}
@@ -152,13 +157,8 @@
return mControl;
}
- void revokeControl() {
- if (mControllingWin != null) {
-
- // Cancelling the animation will invoke onAnimationCancelled, resetting all the fields.
- mWin.cancelAnimation();
- }
- setClientVisible(InsetsState.getDefaultVisibly(mSource.getType()));
+ boolean isClientVisible() {
+ return mClientVisible;
}
private class ControlAdapter implements AnimationAdapter {
@@ -186,6 +186,7 @@
public void onAnimationCancelled(SurfaceControl animationLeash) {
if (mAdapter == this) {
mStateController.notifyControlRevoked(mControllingWin, InsetsSourceProvider.this);
+ setClientVisible(InsetsState.getDefaultVisibly(mSource.getType()));
mControl = null;
mControllingWin = null;
mAdapter = null;
diff --git a/services/core/java/com/android/server/wm/InsetsStateController.java b/services/core/java/com/android/server/wm/InsetsStateController.java
index 8e119bb..cc57b93 100644
--- a/services/core/java/com/android/server/wm/InsetsStateController.java
+++ b/services/core/java/com/android/server/wm/InsetsStateController.java
@@ -218,5 +218,11 @@
void dump(String prefix, PrintWriter pw) {
pw.println(prefix + "WindowInsetsStateController");
mState.dump(prefix + " ", pw);
+ pw.println(prefix + " " + "Control map:");
+ for (int i = mTypeWinControlMap.size() - 1; i >= 0; i--) {
+ pw.print(prefix + " ");
+ pw.println(InsetsState.typeToString(mTypeWinControlMap.keyAt(i)) + " -> "
+ + mTypeWinControlMap.valueAt(i));
+ }
}
}
diff --git a/services/core/java/com/android/server/wm/TaskLaunchParamsModifier.java b/services/core/java/com/android/server/wm/TaskLaunchParamsModifier.java
index da63dc9..6acd864 100644
--- a/services/core/java/com/android/server/wm/TaskLaunchParamsModifier.java
+++ b/services/core/java/com/android/server/wm/TaskLaunchParamsModifier.java
@@ -219,10 +219,16 @@
}
}
- if (launchMode == WINDOWING_MODE_FREEFORM && !currentParams.mBounds.isEmpty()) {
+ if (!currentParams.mBounds.isEmpty()) {
+ // Carry over bounds from callers regardless of launch mode because bounds is still
+ // used to restore last non-fullscreen bounds when launch mode is not freeform.
+ // Therefore it's not a resolution step for non-freeform launch mode and only
+ // consider it fully resolved only when launch mode is freeform.
outParams.mBounds.set(currentParams.mBounds);
- fullyResolvedCurrentParam = true;
- if (DEBUG) appendLog("inherit-bounds=" + outParams.mBounds);
+ if (launchMode == WINDOWING_MODE_FREEFORM) {
+ fullyResolvedCurrentParam = true;
+ if (DEBUG) appendLog("inherit-bounds=" + outParams.mBounds);
+ }
}
}
diff --git a/services/core/java/com/android/server/wm/WindowState.java b/services/core/java/com/android/server/wm/WindowState.java
index e78c12c..cd29b3c 100644
--- a/services/core/java/com/android/server/wm/WindowState.java
+++ b/services/core/java/com/android/server/wm/WindowState.java
@@ -1373,12 +1373,15 @@
@Override
boolean isVisible() {
- return wouldBeVisibleIfPolicyIgnored() && mPolicyVisibility;
+ return wouldBeVisibleIfPolicyIgnored() && mPolicyVisibility
+ // If we don't have a provider, this window isn't used as a window generating
+ // insets, so nobody can hide it over the inset APIs.
+ && (mInsetProvider == null || mInsetProvider.isClientVisible());
}
/**
- * @return True if the window would be visible if we'd ignore policy visibility, false
- * otherwise.
+ * @return {@code true} if the window would be visible if we'd ignore policy visibility,
+ * {@code false} otherwise.
*/
boolean wouldBeVisibleIfPolicyIgnored() {
return mHasSurface && !isParentWindowHidden()
diff --git a/services/tests/uiservicestests/src/com/android/server/notification/BuzzBeepBlinkTest.java b/services/tests/uiservicestests/src/com/android/server/notification/BuzzBeepBlinkTest.java
index 9d84751..20c5f5d 100644
--- a/services/tests/uiservicestests/src/com/android/server/notification/BuzzBeepBlinkTest.java
+++ b/services/tests/uiservicestests/src/com/android/server/notification/BuzzBeepBlinkTest.java
@@ -60,6 +60,7 @@
import android.os.VibrationEffect;
import android.os.Vibrator;
import android.provider.Settings;
+import android.service.notification.NotificationListenerService;
import android.service.notification.StatusBarNotification;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.SmallTest;
@@ -114,7 +115,7 @@
private static final Uri CUSTOM_SOUND = Settings.System.DEFAULT_ALARM_ALERT_URI;
private static final AudioAttributes CUSTOM_ATTRIBUTES = new AudioAttributes.Builder()
.setContentType(AudioAttributes.CONTENT_TYPE_UNKNOWN)
- .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)
+ .setUsage(AudioAttributes.USAGE_VOICE_COMMUNICATION)
.build();
private static final int CUSTOM_LIGHT_COLOR = Color.BLACK;
private static final int CUSTOM_LIGHT_ON = 10000;
@@ -237,11 +238,11 @@
false /* noisy */, false /* buzzy*/, true /* lights */);
}
- private NotificationRecord getCustomLightsNotification() {
- return getNotificationRecord(mId, false /* insistent */, true /* once */,
- false /* noisy */, true /* buzzy*/, true /* lights */,
- true /* defaultVibration */, true /* defaultSound */, false /* defaultLights */,
- null, Notification.GROUP_ALERT_ALL, false);
+ private NotificationRecord getCallRecord(int id, boolean insistent) {
+ return getNotificationRecord(id, false, false /* once */, true /* noisy */,
+ false /* buzzy */, false /* lights */, false /* default vib */,
+ false /* default sound */, false /* default lights */, "",
+ Notification.GROUP_ALERT_ALL, false);
}
private NotificationRecord getNotificationRecord(int id, boolean insistent, boolean once,
@@ -351,11 +352,6 @@
eq(false), (AudioAttributes) anyObject());
}
- private void verifyCustomBeep() throws RemoteException {
- verify(mRingtonePlayer, times(1)).playAsync(eq(CUSTOM_SOUND), (UserHandle) anyObject(),
- eq(false), (AudioAttributes) anyObject());
- }
-
private void verifyNeverStopAudio() throws RemoteException {
verify(mRingtonePlayer, never()).stopAsync();
}
@@ -1015,22 +1011,6 @@
}
@Test
- public void testCanceledNoisyNeverVibrate() throws Exception {
- NotificationRecord r = getBuzzyBeepyNotification();
-
- final int waitMs = mAudioManager.getFocusRampTimeMs(
- AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK,
- r.getAudioAttributes());
-
- mService.buzzBeepBlinkLocked(r);
- mService.clearNotifications();
-
- verifyNeverVibrate();
- Thread.sleep(waitMs);
- verifyNeverVibrate();
- }
-
- @Test
public void testEmptyUriSoundTreatedAsNoSound() throws Exception {
NotificationChannel channel = new NotificationChannel("test", "test", IMPORTANCE_HIGH);
channel.setSound(Uri.EMPTY, null);
@@ -1293,6 +1273,64 @@
assertEquals(-1, group.getLastAudiblyAlertedMs());
}
+ @Test
+ public void testListenerHintCall() throws Exception {
+ NotificationRecord r = getCallRecord(1, true);
+
+ mService.setHints(NotificationListenerService.HINT_HOST_DISABLE_CALL_EFFECTS);
+
+ mService.buzzBeepBlinkLocked(r);
+
+ verifyNeverBeep();
+ }
+
+ @Test
+ public void testListenerHintCall_notificationSound() throws Exception {
+ NotificationRecord r = getBeepyNotification();
+
+ mService.setHints(NotificationListenerService.HINT_HOST_DISABLE_CALL_EFFECTS);
+
+ mService.buzzBeepBlinkLocked(r);
+
+ verifyBeepLooped();
+ }
+
+ @Test
+ public void testListenerHintNotification() throws Exception {
+ NotificationRecord r = getBeepyNotification();
+
+ mService.setHints(NotificationListenerService.HINT_HOST_DISABLE_NOTIFICATION_EFFECTS);
+
+ mService.buzzBeepBlinkLocked(r);
+
+ verifyNeverBeep();
+ }
+
+ @Test
+ public void testListenerHintBoth() throws Exception {
+ NotificationRecord r = getCallRecord(1, true);
+ NotificationRecord s = getBeepyNotification();
+
+ mService.setHints(NotificationListenerService.HINT_HOST_DISABLE_NOTIFICATION_EFFECTS
+ | NotificationListenerService.HINT_HOST_DISABLE_CALL_EFFECTS);
+
+ mService.buzzBeepBlinkLocked(r);
+ mService.buzzBeepBlinkLocked(s);
+
+ verifyNeverBeep();
+ }
+
+ @Test
+ public void testListenerHintNotification_callSound() throws Exception {
+ NotificationRecord r = getCallRecord(1, true);
+
+ mService.setHints(NotificationListenerService.HINT_HOST_DISABLE_NOTIFICATION_EFFECTS);
+
+ mService.buzzBeepBlinkLocked(r);
+
+ verifyBeepLooped();
+ }
+
static class VibrateRepeatMatcher implements ArgumentMatcher<VibrationEffect> {
private final int mRepeatIndex;
diff --git a/services/tests/wmtests/src/com/android/server/wm/TaskLaunchParamsModifierTests.java b/services/tests/wmtests/src/com/android/server/wm/TaskLaunchParamsModifierTests.java
index 41cdcc0..53e99fa 100644
--- a/services/tests/wmtests/src/com/android/server/wm/TaskLaunchParamsModifierTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/TaskLaunchParamsModifierTests.java
@@ -787,6 +787,21 @@
}
@Test
+ public void testReturnBoundsForFullscreenWindowingMode() {
+ final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
+ WINDOWING_MODE_FREEFORM);
+
+ mCurrent.mPreferredDisplayId = freeformDisplay.mDisplayId;
+ mCurrent.mWindowingMode = WINDOWING_MODE_FULLSCREEN;
+ mCurrent.mBounds.set(0, 0, 200, 100);
+
+ assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, /* layout */ null,
+ mActivity, /* source */ null, /* options */ null, mCurrent, mResult));
+
+ assertEquals(new Rect(0, 0, 200, 100), mResult.mBounds);
+ }
+
+ @Test
public void testUsesDisplayOrientationForNoSensorOrientation() {
final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
WINDOWING_MODE_FREEFORM);
diff --git a/services/tests/wmtests/src/com/android/server/wm/WindowStateTests.java b/services/tests/wmtests/src/com/android/server/wm/WindowStateTests.java
index 7f78034..c09cd46 100644
--- a/services/tests/wmtests/src/com/android/server/wm/WindowStateTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/WindowStateTests.java
@@ -19,6 +19,7 @@
import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD;
import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
import static android.hardware.camera2.params.OutputConfiguration.ROTATION_90;
+import static android.view.InsetsState.TYPE_TOP_BAR;
import static android.view.Surface.ROTATION_0;
import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
@@ -31,6 +32,7 @@
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL;
import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
+import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.never;
@@ -56,6 +58,7 @@
import android.platform.test.annotations.Presubmit;
import android.util.Size;
import android.view.DisplayCutout;
+import android.view.InsetsSource;
import android.view.SurfaceControl;
import android.view.WindowManager;
@@ -326,6 +329,20 @@
}
@Test
+ public void testVisibleWithInsetsProvider() throws Exception {
+ final WindowState topBar = createWindow(null, TYPE_STATUS_BAR, "topBar");
+ final WindowState app = createWindow(null, TYPE_APPLICATION, "app");
+ topBar.mHasSurface = true;
+ assertTrue(topBar.isVisible());
+ mDisplayContent.getInsetsStateController().getSourceProvider(TYPE_TOP_BAR)
+ .setWindow(topBar, null);
+ mDisplayContent.getInsetsStateController().onBarControllingWindowChanged(app);
+ mDisplayContent.getInsetsStateController().getSourceProvider(TYPE_TOP_BAR)
+ .onInsetsModified(app, new InsetsSource(TYPE_TOP_BAR));
+ assertFalse(topBar.isVisible());
+ }
+
+ @Test
public void testIsSelfOrAncestorWindowAnimating() {
final WindowState root = createWindow(null, TYPE_APPLICATION, "root");
final WindowState child1 = createWindow(root, FIRST_SUB_WINDOW, "child1");
diff --git a/tests/net/java/android/net/NetworkStatsTest.java b/tests/net/java/android/net/NetworkStatsTest.java
index 1e3a49b..2c2afd4 100644
--- a/tests/net/java/android/net/NetworkStatsTest.java
+++ b/tests/net/java/android/net/NetworkStatsTest.java
@@ -832,25 +832,23 @@
0 /* operations */);
// Traffic measured for the root uid on the base interface if eBPF is in use.
- // Incorrectly includes appEntry's bytes and packets, plus IPv4-IPv6 translation
- // overhead (20 bytes per packet), only for TX traffic.
final NetworkStats.Entry ebpfRootUidEntry = new NetworkStats.Entry(
baseIface, rootUid, SET_DEFAULT, TAG_NONE,
163577 /* rxBytes */,
187 /* rxPackets */,
- 1169942 /* txBytes */,
- 13902 /* txPackets */,
+ 17607 /* txBytes */,
+ 97 /* txPackets */,
0 /* operations */);
// Traffic measured for the root uid on the base interface if xt_qtaguid is in use.
// Incorrectly includes appEntry's bytes and packets, plus IPv4-IPv6 translation
- // overhead (20 bytes per packet), in both directions.
+ // overhead (20 bytes per packet), in rx direction.
final NetworkStats.Entry xtRootUidEntry = new NetworkStats.Entry(
baseIface, rootUid, SET_DEFAULT, TAG_NONE,
31113087 /* rxBytes */,
22588 /* rxPackets */,
- 1169942 /* txBytes */,
- 13902 /* txPackets */,
+ 17607 /* txBytes */,
+ 97 /* txPackets */,
0 /* operations */);
final NetworkStats.Entry otherEntry = new NetworkStats.Entry(
diff --git a/tests/net/java/com/android/internal/net/NetworkStatsFactoryTest.java b/tests/net/java/com/android/internal/net/NetworkStatsFactoryTest.java
index 788924b..90bf7b1 100644
--- a/tests/net/java/com/android/internal/net/NetworkStatsFactoryTest.java
+++ b/tests/net/java/com/android/internal/net/NetworkStatsFactoryTest.java
@@ -159,7 +159,7 @@
assertStatsEntry(stats, "v4-wlan0", 1000, SET_DEFAULT, 0x0, 30812L, 2310L);
assertStatsEntry(stats, "v4-wlan0", 10102, SET_DEFAULT, 0x0, 10022L, 3330L);
assertStatsEntry(stats, "v4-wlan0", 10060, SET_DEFAULT, 0x0, 9532772L, 254112L);
- assertStatsEntry(stats, "wlan0", 0, SET_DEFAULT, 0x0, 15229L, 5766L);
+ assertStatsEntry(stats, "wlan0", 0, SET_DEFAULT, 0x0, 15229L, 0L);
assertStatsEntry(stats, "wlan0", 1000, SET_DEFAULT, 0x0, 6126L, 2013L);
assertStatsEntry(stats, "wlan0", 10013, SET_DEFAULT, 0x0, 0L, 144L);
assertStatsEntry(stats, "wlan0", 10018, SET_DEFAULT, 0x0, 5980263L, 167667L);
@@ -170,6 +170,8 @@
assertStatsEntry(stats, "dummy0", 0, SET_DEFAULT, 0x0, 0L, 168L);
assertStatsEntry(stats, "lo", 0, SET_DEFAULT, 0x0, 1288L, 1288L);
+ assertNoStatsEntry(stats, "wlan0", 1029, SET_DEFAULT, 0x0);
+
NetworkStatsFactory.clearStackedIfaces();
}
@@ -191,12 +193,12 @@
// Stats snapshot before the download
stats = parseDetailedStats(R.raw.xt_qtaguid_with_clat_100mb_download_before);
assertStatsEntry(stats, "v4-wlan0", 10106, SET_FOREGROUND, 0x0, appRxBytesBefore, 5199872L);
- assertStatsEntry(stats, "wlan0", 0, SET_DEFAULT, 0x0, rootRxBytesBefore, 647888L);
+ assertStatsEntry(stats, "wlan0", 0, SET_DEFAULT, 0x0, rootRxBytesBefore, 0L);
// Stats snapshot after the download
stats = parseDetailedStats(R.raw.xt_qtaguid_with_clat_100mb_download_after);
assertStatsEntry(stats, "v4-wlan0", 10106, SET_FOREGROUND, 0x0, appRxBytesAfter, 7867488L);
- assertStatsEntry(stats, "wlan0", 0, SET_DEFAULT, 0x0, rootRxBytesAfter, 647587L);
+ assertStatsEntry(stats, "wlan0", 0, SET_DEFAULT, 0x0, rootRxBytesAfter, 0L);
NetworkStatsFactory.clearStackedIfaces();
}
@@ -252,6 +254,15 @@
assertEquals("unexpected txBytes", txBytes, entry.txBytes);
}
+ private static void assertNoStatsEntry(NetworkStats stats, String iface, int uid, int set,
+ int tag) {
+ final int i = stats.findIndex(iface, uid, set, tag, METERED_NO, ROAMING_NO,
+ DEFAULT_NETWORK_NO);
+ if (i >= 0) {
+ fail("unexpected NetworkStats entry at " + i);
+ }
+ }
+
private static void assertStatsEntry(NetworkStats stats, String iface, int uid, int set,
int tag, long rxBytes, long rxPackets, long txBytes, long txPackets) {
final int i = stats.findIndex(iface, uid, set, tag, METERED_NO, ROAMING_NO,
diff --git a/tests/net/res/raw/xt_qtaguid_with_clat b/tests/net/res/raw/xt_qtaguid_with_clat
index 77e5c7b..6cd7499 100644
--- a/tests/net/res/raw/xt_qtaguid_with_clat
+++ b/tests/net/res/raw/xt_qtaguid_with_clat
@@ -7,7 +7,7 @@
7 v4-wlan0 0x0 10060 1 1448660 1041 31192 753 1448660 1041 0 0 0 0 31192 753 0 0 0 0
8 v4-wlan0 0x0 10102 0 9702 16 2870 23 9702 16 0 0 0 0 2870 23 0 0 0 0
9 v4-wlan0 0x0 10102 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
-10 wlan0 0x0 0 0 11058671 7892 312046 5113 11043898 7811 13117 61 1656 20 306544 5046 3230 38 2272 29
+10 wlan0 0x0 0 0 11058671 7892 0 0 11043898 7811 13117 61 1656 20 0 0 0 0 0 0
11 wlan0 0x0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
12 wlan0 0x0 1000 0 6126 13 2013 16 5934 11 192 2 0 0 1821 14 192 2 0 0
13 wlan0 0x0 1000 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
@@ -41,3 +41,5 @@
41 dummy0 0x0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
42 lo 0x0 0 0 1288 16 1288 16 0 0 532 8 756 8 0 0 532 8 756 8
43 lo 0x0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+44 wlan0 0x0 1029 0 0 0 312046 5113 0 0 0 0 0 0 306544 5046 3230 38 2272 29
+45 wlan0 0x0 1029 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
\ No newline at end of file
diff --git a/tests/net/res/raw/xt_qtaguid_with_clat_100mb_download_after b/tests/net/res/raw/xt_qtaguid_with_clat_100mb_download_after
index c78f84f..9f86153 100644
--- a/tests/net/res/raw/xt_qtaguid_with_clat_100mb_download_after
+++ b/tests/net/res/raw/xt_qtaguid_with_clat_100mb_download_after
@@ -9,7 +9,7 @@
9 v4-wlan0 0x0 10057 1 728 7 392 7 0 0 728 7 0 0 0 0 392 7 0 0
10 v4-wlan0 0x0 10106 0 2232 18 2232 18 0 0 2232 18 0 0 0 0 2232 18 0 0
11 v4-wlan0 0x0 10106 1 432952718 314238 5442288 121260 432950238 314218 2480 20 0 0 5433900 121029 8388 231 0 0
-12 wlan0 0x0 0 0 440746376 329772 8524052 130894 439660007 315369 232001 1276 854368 13127 7871216 121284 108568 1325 544268 8285
+12 wlan0 0x0 0 0 440746376 329772 0 0 439660007 315369 232001 1276 854368 13127 0 0 0 0 0 0
13 wlan0 0x0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
14 wlan0 0x0 1000 0 77113 272 56151 575 77113 272 0 0 0 0 19191 190 36960 385 0 0
15 wlan0 0x0 1000 1 20227 80 8356 72 18539 74 1688 6 0 0 7562 66 794 6 0 0
@@ -185,3 +185,5 @@
185 wlan0 0xffffff0900000000 1000 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
186 dummy0 0x0 0 0 0 0 168 3 0 0 0 0 0 0 0 0 0 0 168 3
187 dummy0 0x0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+188 wlan0 0x0 1029 0 0 0 8524052 130894 0 0 0 0 0 0 7871216 121284 108568 1325 544268 8285
+189 wlan0 0x0 1029 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
diff --git a/tests/net/res/raw/xt_qtaguid_with_clat_100mb_download_before b/tests/net/res/raw/xt_qtaguid_with_clat_100mb_download_before
index d035387..ce4bcc3 100644
--- a/tests/net/res/raw/xt_qtaguid_with_clat_100mb_download_before
+++ b/tests/net/res/raw/xt_qtaguid_with_clat_100mb_download_before
@@ -9,7 +9,7 @@
9 v4-wlan0 0x0 10057 1 728 7 392 7 0 0 728 7 0 0 0 0 392 7 0 0
10 v4-wlan0 0x0 10106 0 1488 12 1488 12 0 0 1488 12 0 0 0 0 1488 12 0 0
11 v4-wlan0 0x0 10106 1 323981189 235142 3509032 84542 323979453 235128 1736 14 0 0 3502676 84363 6356 179 0 0
-12 wlan0 0x0 0 0 330187296 250652 5855801 94173 329106990 236273 226202 1255 854104 13124 5208040 84634 103637 1256 544124 8283
+12 wlan0 0x0 0 0 330187296 250652 0 0 329106990 236273 226202 1255 854104 13124 0 0 0 0 0 0
13 wlan0 0x0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
14 wlan0 0x0 1000 0 77113 272 56151 575 77113 272 0 0 0 0 19191 190 36960 385 0 0
15 wlan0 0x0 1000 1 20227 80 8356 72 18539 74 1688 6 0 0 7562 66 794 6 0 0
@@ -183,3 +183,5 @@
183 wlan0 0xffffff0900000000 1000 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
184 dummy0 0x0 0 0 0 0 168 3 0 0 0 0 0 0 0 0 0 0 168 3
185 dummy0 0x0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+186 wlan0 0x0 1029 0 0 0 5855801 94173 0 0 0 0 0 0 5208040 84634 103637 1256 544124 8283
+187 wlan0 0x0 1029 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
diff --git a/tests/net/res/raw/xt_qtaguid_with_clat_simple b/tests/net/res/raw/xt_qtaguid_with_clat_simple
index 7f0e56f..8c132e7 100644
--- a/tests/net/res/raw/xt_qtaguid_with_clat_simple
+++ b/tests/net/res/raw/xt_qtaguid_with_clat_simple
@@ -1,5 +1,6 @@
idx iface acct_tag_hex uid_tag_int cnt_set rx_bytes rx_packets tx_bytes tx_packets rx_tcp_bytes rx_tcp_packets rx_udp_bytes rx_udp_packets rx_other_bytes rx_other_packets tx_tcp_bytes tx_tcp_packets tx_udp_bytes tx_udp_packets tx_other_bytes tx_other_packets
-2 v4-wlan0 0x0 10060 0 42600 213 4100 41 42600 213 4100 41 0 0 0 0 0 0 0 0
+2 v4-wlan0 0x0 10060 0 42600 213 4100 41 42600 213 0 0 0 0 4100 41 0 0 0 0
3 v4-wlan0 0x0 10060 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
-4 wlan0 0x0 0 0 46860 213 4920 41 46860 213 4920 41 0 0 0 0 0 0 0 0
+4 wlan0 0x0 0 0 46860 213 0 0 46860 213 0 0 0 0 0 0 0 0 0 0
5 wlan0 0x0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+6 wlan0 0x0 1029 0 0 0 4920 41 0 0 0 0 0 0 4920 41 0 0 0 0
diff --git a/tools/aapt/ConfigDescription.h b/tools/aapt/ConfigDescription.h
index 09430f2..b4ea624 100644
--- a/tools/aapt/ConfigDescription.h
+++ b/tools/aapt/ConfigDescription.h
@@ -29,7 +29,7 @@
size = sizeof(android::ResTable_config);
}
- ConfigDescription(const android::ResTable_config&o) { // NOLINT(implicit)
+ ConfigDescription(const android::ResTable_config&o) { // NOLINT(google-explicit-constructor)
*static_cast<android::ResTable_config*>(this) = o;
size = sizeof(android::ResTable_config);
}
diff --git a/tools/aapt2/Android.bp b/tools/aapt2/Android.bp
index ba498e1..c42a888 100644
--- a/tools/aapt2/Android.bp
+++ b/tools/aapt2/Android.bp
@@ -170,6 +170,7 @@
srcs: [
"test/Builders.cpp",
"test/Common.cpp",
+ "test/Fixture.cpp",
"**/*_test.cpp",
] + toolSources,
static_libs: [
@@ -177,7 +178,10 @@
"libgmock",
],
defaults: ["aapt2_defaults"],
- data: ["integration-tests/CompileTest/**/*"],
+ data: [
+ "integration-tests/CompileTest/**/*",
+ "integration-tests/CommandTests/**/*"
+ ],
}
// ==========================================================
diff --git a/tools/aapt2/Debug.cpp b/tools/aapt2/Debug.cpp
index 9460c9e..5f664f5 100644
--- a/tools/aapt2/Debug.cpp
+++ b/tools/aapt2/Debug.cpp
@@ -445,7 +445,7 @@
public:
using xml::ConstVisitor::Visit;
- XmlPrinter(Printer* printer) : printer_(printer) {
+ explicit XmlPrinter(Printer* printer) : printer_(printer) {
}
void Visit(const xml::Element* el) override {
diff --git a/tools/aapt2/Resource.h b/tools/aapt2/Resource.h
index dd5c751..67ba895 100644
--- a/tools/aapt2/Resource.h
+++ b/tools/aapt2/Resource.h
@@ -113,7 +113,7 @@
ResourceNameRef() = default;
ResourceNameRef(const ResourceNameRef&) = default;
ResourceNameRef(ResourceNameRef&&) = default;
- ResourceNameRef(const ResourceName& rhs); // NOLINT(implicit)
+ ResourceNameRef(const ResourceName& rhs); // NOLINT(google-explicit-constructor)
ResourceNameRef(const android::StringPiece& p, ResourceType t, const android::StringPiece& e);
ResourceNameRef& operator=(const ResourceNameRef& rhs) = default;
ResourceNameRef& operator=(ResourceNameRef&& rhs) = default;
@@ -144,7 +144,7 @@
ResourceId();
ResourceId(const ResourceId& rhs);
- ResourceId(uint32_t res_id); // NOLINT(implicit)
+ ResourceId(uint32_t res_id); // NOLINT(google-explicit-constructor)
ResourceId(uint8_t p, uint8_t t, uint16_t e);
bool is_valid() const;
diff --git a/tools/aapt2/cmd/Compile.cpp b/tools/aapt2/cmd/Compile.cpp
index f63a074..52375a3 100644
--- a/tools/aapt2/cmd/Compile.cpp
+++ b/tools/aapt2/cmd/Compile.cpp
@@ -584,7 +584,7 @@
class CompileContext : public IAaptContext {
public:
- CompileContext(IDiagnostics* diagnostics) : diagnostics_(diagnostics) {
+ explicit CompileContext(IDiagnostics* diagnostics) : diagnostics_(diagnostics) {
}
PackageType GetPackageType() override {
diff --git a/tools/aapt2/cmd/Convert.cpp b/tools/aapt2/cmd/Convert.cpp
index 4492f6b..85f9080 100644
--- a/tools/aapt2/cmd/Convert.cpp
+++ b/tools/aapt2/cmd/Convert.cpp
@@ -60,16 +60,17 @@
class BinaryApkSerializer : public IApkSerializer {
public:
BinaryApkSerializer(IAaptContext* context, const Source& source,
- const TableFlattenerOptions& options)
- : IApkSerializer(context, source), tableFlattenerOptions_(options) {}
+ const TableFlattenerOptions& table_flattener_options,
+ const XmlFlattenerOptions& xml_flattener_options)
+ : IApkSerializer(context, source),
+ table_flattener_options_(table_flattener_options),
+ xml_flattener_options_(xml_flattener_options) {}
bool SerializeXml(const xml::XmlResource* xml, const std::string& path, bool utf16,
IArchiveWriter* writer, uint32_t compression_flags) override {
BigBuffer buffer(4096);
- XmlFlattenerOptions options = {};
- options.use_utf16 = utf16;
- options.keep_raw_values = true;
- XmlFlattener flattener(&buffer, options);
+ xml_flattener_options_.use_utf16 = utf16;
+ XmlFlattener flattener(&buffer, xml_flattener_options_);
if (!flattener.Consume(context_, xml)) {
return false;
}
@@ -80,7 +81,7 @@
bool SerializeTable(ResourceTable* table, IArchiveWriter* writer) override {
BigBuffer buffer(4096);
- TableFlattener table_flattener(tableFlattenerOptions_, &buffer);
+ TableFlattener table_flattener(table_flattener_options_, &buffer);
if (!table_flattener.Consume(context_, table)) {
return false;
}
@@ -136,7 +137,8 @@
}
private:
- TableFlattenerOptions tableFlattenerOptions_;
+ TableFlattenerOptions table_flattener_options_;
+ XmlFlattenerOptions xml_flattener_options_;
DISALLOW_COPY_AND_ASSIGN(BinaryApkSerializer);
};
@@ -252,13 +254,15 @@
};
int Convert(IAaptContext* context, LoadedApk* apk, IArchiveWriter* output_writer,
- ApkFormat output_format, TableFlattenerOptions& options) {
+ ApkFormat output_format, TableFlattenerOptions table_flattener_options,
+ XmlFlattenerOptions xml_flattener_options) {
// Do not change the ordering of strings in the values string pool
- options.sort_stringpool_entries = false;
+ table_flattener_options.sort_stringpool_entries = false;
unique_ptr<IApkSerializer> serializer;
if (output_format == ApkFormat::kBinary) {
- serializer.reset(new BinaryApkSerializer(context, apk->GetSource(), options));
+ serializer.reset(new BinaryApkSerializer(context, apk->GetSource(), table_flattener_options,
+ xml_flattener_options));
} else if (output_format == ApkFormat::kProto) {
serializer.reset(new ProtoApkSerializer(context, apk->GetSource()));
} else {
@@ -378,7 +382,8 @@
return 1;
}
- return Convert(&context, apk.get(), writer.get(), format, options_);
+ return Convert(&context, apk.get(), writer.get(), format, table_flattener_options_,
+ xml_flattener_options_);
}
} // namespace aapt
diff --git a/tools/aapt2/cmd/Convert.h b/tools/aapt2/cmd/Convert.h
index 14016b1..7e2029d 100644
--- a/tools/aapt2/cmd/Convert.h
+++ b/tools/aapt2/cmd/Convert.h
@@ -20,6 +20,7 @@
#include "Command.h"
#include "LoadedApk.h"
#include "format/binary/TableFlattener.h"
+#include "format/binary/XmlFlattener.h"
namespace aapt {
@@ -33,8 +34,12 @@
kOutputFormatProto, kOutputFormatBinary, kOutputFormatBinary), &output_format_);
AddOptionalSwitch("--enable-sparse-encoding",
"Enables encoding sparse entries using a binary search tree.\n"
- "This decreases APK size at the cost of resource retrieval performance.",
- &options_.use_sparse_entries);
+ "This decreases APK size at the cost of resource retrieval performance.",
+ &table_flattener_options_.use_sparse_entries);
+ AddOptionalSwitch("--keep-raw-values",
+ android::base::StringPrintf("Preserve raw attribute values in xml files when using the"
+ " '%s' output format", kOutputFormatBinary),
+ &xml_flattener_options_.keep_raw_values);
AddOptionalSwitch("-v", "Enables verbose logging", &verbose_);
}
@@ -44,14 +49,16 @@
const static char* kOutputFormatProto;
const static char* kOutputFormatBinary;
- TableFlattenerOptions options_;
+ TableFlattenerOptions table_flattener_options_;
+ XmlFlattenerOptions xml_flattener_options_;
std::string output_path_;
Maybe<std::string> output_format_;
bool verbose_ = false;
};
int Convert(IAaptContext* context, LoadedApk* input, IArchiveWriter* output_writer,
- ApkFormat output_format, TableFlattenerOptions& options);
+ ApkFormat output_format,TableFlattenerOptions table_flattener_options,
+ XmlFlattenerOptions xml_flattener_options);
} // namespace aapt
diff --git a/tools/aapt2/cmd/Convert_test.cpp b/tools/aapt2/cmd/Convert_test.cpp
new file mode 100644
index 0000000..2e43150
--- /dev/null
+++ b/tools/aapt2/cmd/Convert_test.cpp
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "Convert.h"
+
+#include "LoadedApk.h"
+#include "test/Test.h"
+
+using testing::Eq;
+using testing::Ne;
+
+namespace aapt {
+
+using ConvertTest = CommandTestFixture;
+
+TEST_F(ConvertTest, RemoveRawXmlStrings) {
+ StdErrDiagnostics diag;
+ const std::string compiled_files_dir = GetTestPath("compiled");
+ ASSERT_TRUE(CompileFile(GetTestPath("res/xml/test.xml"), R"(<Item AgentCode="007"/>)",
+ compiled_files_dir, &diag));
+
+ const std::string out_apk = GetTestPath("out.apk");
+ std::vector<std::string> link_args = {
+ "--manifest", GetDefaultManifest(),
+ "-o", out_apk,
+ "--keep-raw-values",
+ "--proto-format"
+ };
+
+ ASSERT_TRUE(Link(link_args, compiled_files_dir, &diag));
+
+ const std::string out_convert_apk = GetTestPath("out_convert.apk");
+ std::vector<android::StringPiece> convert_args = {
+ "-o", out_convert_apk,
+ "--output-format", "binary",
+ out_apk,
+ };
+ ASSERT_THAT(ConvertCommand().Execute(convert_args, &std::cerr), Eq(0));
+
+ // Load the binary xml tree
+ android::ResXMLTree tree;
+ std::unique_ptr<LoadedApk> apk = LoadedApk::LoadApkFromPath(out_convert_apk, &diag);
+ AssertLoadXml(apk.get(), "res/xml/test.xml", &tree);
+
+ // Check that the raw string index has not been assigned
+ EXPECT_THAT(tree.getAttributeValueStringID(0), Eq(-1));
+}
+
+TEST_F(ConvertTest, KeepRawXmlStrings) {
+ StdErrDiagnostics diag;
+ const std::string compiled_files_dir = GetTestPath("compiled");
+ ASSERT_TRUE(CompileFile(GetTestPath("res/xml/test.xml"), R"(<Item AgentCode="007"/>)",
+ compiled_files_dir, &diag));
+
+ const std::string out_apk = GetTestPath("out.apk");
+ std::vector<std::string> link_args = {
+ "--manifest", GetDefaultManifest(),
+ "-o", out_apk,
+ "--keep-raw-values",
+ "--proto-format"
+ };
+
+ ASSERT_TRUE(Link(link_args, compiled_files_dir, &diag));
+
+ const std::string out_convert_apk = GetTestPath("out_convert.apk");
+ std::vector<android::StringPiece> convert_args = {
+ "-o", out_convert_apk,
+ "--output-format", "binary",
+ "--keep-raw-values",
+ out_apk,
+ };
+ ASSERT_THAT(ConvertCommand().Execute(convert_args, &std::cerr), Eq(0));
+
+ // Load the binary xml tree
+ android::ResXMLTree tree;
+ std::unique_ptr<LoadedApk> apk = LoadedApk::LoadApkFromPath(out_convert_apk, &diag);
+ AssertLoadXml(apk.get(), "res/xml/test.xml", &tree);
+
+ // Check that the raw string index has been set to the correct string pool entry
+ int32_t raw_index = tree.getAttributeValueStringID(0);
+ ASSERT_THAT(raw_index, Ne(-1));
+ EXPECT_THAT(util::GetString(tree.getStrings(), static_cast<size_t>(raw_index)), Eq("007"));
+}
+
+} // namespace aapt
\ No newline at end of file
diff --git a/tools/aapt2/cmd/Link.cpp b/tools/aapt2/cmd/Link.cpp
index 1b5601d..729447e 100644
--- a/tools/aapt2/cmd/Link.cpp
+++ b/tools/aapt2/cmd/Link.cpp
@@ -78,7 +78,7 @@
class LinkContext : public IAaptContext {
public:
- LinkContext(IDiagnostics* diagnostics)
+ explicit LinkContext(IDiagnostics* diagnostics)
: diagnostics_(diagnostics), name_mangler_({}), symbols_(&name_mangler_) {
}
@@ -163,7 +163,7 @@
// See b/37498913.
class FeatureSplitSymbolTableDelegate : public DefaultSymbolTableDelegate {
public:
- FeatureSplitSymbolTableDelegate(IAaptContext* context) : context_(context) {
+ explicit FeatureSplitSymbolTableDelegate(IAaptContext* context) : context_(context) {
}
virtual ~FeatureSplitSymbolTableDelegate() = default;
@@ -1545,7 +1545,8 @@
// to the IArchiveWriter.
bool WriteApk(IArchiveWriter* writer, proguard::KeepSet* keep_set, xml::XmlResource* manifest,
ResourceTable* table) {
- const bool keep_raw_values = context_->GetPackageType() == PackageType::kStaticLib;
+ const bool keep_raw_values = (context_->GetPackageType() == PackageType::kStaticLib)
+ || options_.keep_raw_values;
bool result = FlattenXml(context_, *manifest, kAndroidManifestPath, keep_raw_values,
true /*utf16*/, options_.output_format, writer);
if (!result) {
diff --git a/tools/aapt2/cmd/Link.h b/tools/aapt2/cmd/Link.h
index f740d53..f70470a 100644
--- a/tools/aapt2/cmd/Link.h
+++ b/tools/aapt2/cmd/Link.h
@@ -75,6 +75,7 @@
// Flattening options.
TableFlattenerOptions table_flattener_options;
+ bool keep_raw_values = false;
// Split APK options.
TableSplitterOptions table_splitter_options;
@@ -244,6 +245,8 @@
&options_.extensions_to_not_compress);
AddOptionalSwitch("--no-compress", "Do not compress any resources.",
&options_.do_not_compress_anything);
+ AddOptionalSwitch("--keep-raw-values", "Preserve raw attribute values in xml files.",
+ &options_.keep_raw_values);
AddOptionalSwitch("--warn-manifest-validation",
"Treat manifest validation errors as warnings.",
&options_.manifest_fixer_options.warn_validation);
@@ -252,7 +255,6 @@
"Syntax: path/to/output.apk:<config>[,<config>[...]].\n"
"On Windows, use a semicolon ';' separator instead.",
&split_args_);
- AddOptionalSwitch("-v", "Enables verbose logging.", &verbose_);
AddOptionalSwitch("--debug-mode",
"Inserts android:debuggable=\"true\" in to the application node of the\n"
"manifest, making the application debuggable even on production devices.",
@@ -260,6 +262,7 @@
AddOptionalSwitch("--strict-visibility",
"Do not allow overlays with different visibility levels.",
&options_.strict_visibility);
+ AddOptionalSwitch("-v", "Enables verbose logging.", &verbose_);
}
int Action(const std::vector<std::string>& args) override;
diff --git a/tools/aapt2/cmd/Link_test.cpp b/tools/aapt2/cmd/Link_test.cpp
new file mode 100644
index 0000000..3c8b72d
--- /dev/null
+++ b/tools/aapt2/cmd/Link_test.cpp
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "Link.h"
+
+#include "LoadedApk.h"
+#include "test/Test.h"
+
+using testing::Eq;
+using testing::Ne;
+
+namespace aapt {
+
+using LinkTest = CommandTestFixture;
+
+TEST_F(LinkTest, RemoveRawXmlStrings) {
+ StdErrDiagnostics diag;
+ const std::string compiled_files_dir = GetTestPath("compiled");
+ ASSERT_TRUE(CompileFile(GetTestPath("res/xml/test.xml"), R"(<Item AgentCode="007"/>)",
+ compiled_files_dir, &diag));
+
+ const std::string out_apk = GetTestPath("out.apk");
+ std::vector<std::string> link_args = {
+ "--manifest", GetDefaultManifest(),
+ "-o", out_apk,
+ };
+
+ ASSERT_TRUE(Link(link_args, compiled_files_dir, &diag));
+
+ // Load the binary xml tree
+ android::ResXMLTree tree;
+ std::unique_ptr<LoadedApk> apk = LoadedApk::LoadApkFromPath(out_apk, &diag);
+ AssertLoadXml(apk.get(), "res/xml/test.xml", &tree);
+
+ // Check that the raw string index has not been assigned
+ EXPECT_THAT(tree.getAttributeValueStringID(0), Eq(-1));
+}
+
+TEST_F(LinkTest, KeepRawXmlStrings) {
+ StdErrDiagnostics diag;
+ const std::string compiled_files_dir = GetTestPath("compiled");
+ ASSERT_TRUE(CompileFile(GetTestPath("res/xml/test.xml"), R"(<Item AgentCode="007"/>)",
+ compiled_files_dir, &diag));
+
+ const std::string out_apk = GetTestPath("out.apk");
+ std::vector<std::string> link_args = {
+ "--manifest", GetDefaultManifest(),
+ "-o", out_apk,
+ "--keep-raw-values"
+ };
+
+ ASSERT_TRUE(Link(link_args, compiled_files_dir, &diag));
+
+ // Load the binary xml tree
+ android::ResXMLTree tree;
+ std::unique_ptr<LoadedApk> apk = LoadedApk::LoadApkFromPath(out_apk, &diag);
+ AssertLoadXml(apk.get(), "res/xml/test.xml", &tree);
+
+ // Check that the raw string index has been set to the correct string pool entry
+ int32_t raw_index = tree.getAttributeValueStringID(0);
+ ASSERT_THAT(raw_index, Ne(-1));
+ EXPECT_THAT(util::GetString(tree.getStrings(), static_cast<size_t>(raw_index)), Eq("007"));
+}
+
+} // namespace aapt
\ No newline at end of file
diff --git a/tools/aapt2/integration-tests/CommandTests/android-28.jar b/tools/aapt2/integration-tests/CommandTests/android-28.jar
new file mode 100644
index 0000000..ef7576d
--- /dev/null
+++ b/tools/aapt2/integration-tests/CommandTests/android-28.jar
Binary files differ
diff --git a/tools/aapt2/java/ProguardRules.h b/tools/aapt2/java/ProguardRules.h
index 38b4860..f9656d1 100644
--- a/tools/aapt2/java/ProguardRules.h
+++ b/tools/aapt2/java/ProguardRules.h
@@ -49,7 +49,7 @@
public:
KeepSet() = default;
- KeepSet(bool conditional_keep_rules) : conditional_keep_rules_(conditional_keep_rules) {
+ explicit KeepSet(bool conditional_keep_rules) : conditional_keep_rules_(conditional_keep_rules) {
}
inline void AddManifestClass(const UsageLocation& file, const std::string& class_name) {
diff --git a/tools/aapt2/link/XmlCompatVersioner.h b/tools/aapt2/link/XmlCompatVersioner.h
index 099e23c..9980618 100644
--- a/tools/aapt2/link/XmlCompatVersioner.h
+++ b/tools/aapt2/link/XmlCompatVersioner.h
@@ -55,7 +55,7 @@
public:
using Rules = std::unordered_map<ResourceId, std::unique_ptr<IDegradeRule>>;
- XmlCompatVersioner(const Rules* rules);
+ explicit XmlCompatVersioner(const Rules* rules);
std::vector<std::unique_ptr<xml::XmlResource>> Process(IAaptContext* context,
xml::XmlResource* doc,
@@ -83,7 +83,7 @@
class DegradeToManyRule : public IDegradeRule {
public:
- DegradeToManyRule(std::vector<ReplacementAttr> attrs);
+ explicit DegradeToManyRule(std::vector<ReplacementAttr> attrs);
virtual ~DegradeToManyRule() = default;
std::vector<DegradeResult> Degrade(const xml::Element& src_el, const xml::Attribute& src_attr,
diff --git a/tools/aapt2/process/SymbolTable.h b/tools/aapt2/process/SymbolTable.h
index 51a2e37..2d8bd02 100644
--- a/tools/aapt2/process/SymbolTable.h
+++ b/tools/aapt2/process/SymbolTable.h
@@ -71,7 +71,7 @@
bool is_dynamic = false;
};
- SymbolTable(NameMangler* mangler);
+ explicit SymbolTable(NameMangler* mangler);
// Overrides the default ISymbolTableDelegate, which allows a custom defined strategy for
// looking up resources from a set of sources.
diff --git a/tools/aapt2/test/Common.h b/tools/aapt2/test/Common.h
index 50b41f1..777ca5c 100644
--- a/tools/aapt2/test/Common.h
+++ b/tools/aapt2/test/Common.h
@@ -173,10 +173,12 @@
template <typename TValue>
class ValueEqMatcher {
public:
+ // NOLINTNEXTLINE(google-explicit-constructor)
ValueEqMatcher(TValue expected) : expected_(std::move(expected)) {
}
template <typename T>
+ // NOLINTNEXTLINE(google-explicit-constructor)
operator ::testing::Matcher<T>() const {
return ::testing::Matcher<T>(new ValueEqImpl<T>(&expected_));
}
@@ -188,10 +190,12 @@
template <typename TValue>
class ValueEqPointerMatcher {
public:
+ // NOLINTNEXTLINE(google-explicit-constructor)
ValueEqPointerMatcher(const TValue* expected) : expected_(expected) {
}
template <typename T>
+ // NOLINTNEXTLINE(google-explicit-constructor)
operator ::testing::Matcher<T>() const {
return ::testing::Matcher<T>(new ValueEqImpl<T>(expected_));
}
diff --git a/tools/aapt2/test/Fixture.cpp b/tools/aapt2/test/Fixture.cpp
new file mode 100644
index 0000000..aae79fa
--- /dev/null
+++ b/tools/aapt2/test/Fixture.cpp
@@ -0,0 +1,154 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "test/Fixture.h"
+
+#include <dirent.h>
+
+#include "android-base/errors.h"
+#include "android-base/file.h"
+#include "android-base/stringprintf.h"
+#include "android-base/utf8.h"
+#include "androidfw/StringPiece.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+#include "cmd/Compile.h"
+#include "cmd/Link.h"
+#include "io/FileStream.h"
+#include "io/Util.h"
+#include "util/Files.h"
+
+using testing::Eq;
+using testing::Ne;
+
+namespace aapt {
+
+void ClearDirectory(const android::StringPiece& path) {
+ const std::string root_dir = path.to_string();
+ std::unique_ptr<DIR, decltype(closedir)*> dir(opendir(root_dir.data()), closedir);
+ if (!dir) {
+ StdErrDiagnostics().Error(DiagMessage() << android::base::SystemErrorCodeToString(errno));
+ return;
+ }
+
+ while (struct dirent* entry = readdir(dir.get())) {
+ // Do not delete hidden files and do not recurse to the parent of this directory
+ if (util::StartsWith(entry->d_name, ".")) {
+ continue;
+ }
+
+ std::string full_path = file::BuildPath({root_dir, entry->d_name});
+ if (file::GetFileType(full_path) == file::FileType::kDirectory) {
+ ClearDirectory(full_path);
+#ifdef _WIN32
+ _rmdir(full_path.c_str());
+#else
+ rmdir(full_path.c_str());
+#endif
+ } else {
+ android::base::utf8::unlink(full_path.c_str());
+ }
+ }
+}
+
+void TestDirectoryFixture::SetUp() {
+ temp_dir_ = file::BuildPath({android::base::GetExecutableDirectory(),
+ "_temp",
+ testing::UnitTest::GetInstance()->current_test_case()->name(),
+ testing::UnitTest::GetInstance()->current_test_info()->name()});
+ ASSERT_TRUE(file::mkdirs(temp_dir_));
+ ClearDirectory(temp_dir_);
+}
+
+void TestDirectoryFixture::TearDown() {
+ ClearDirectory(temp_dir_);
+}
+
+bool TestDirectoryFixture::WriteFile(const std::string& path, const std::string& contents) {
+ CHECK(util::StartsWith(path, temp_dir_))
+ << "Attempting to create a file outside of test temporary directory.";
+
+ // Create any intermediate directories specified in the path
+ auto pos = std::find(path.rbegin(), path.rend(), file::sDirSep);
+ if (pos != path.rend()) {
+ std::string dirs = path.substr(0, (&*pos - path.data()));
+ file::mkdirs(dirs);
+ }
+
+ return android::base::WriteStringToFile(contents, path);
+}
+
+bool CommandTestFixture::CompileFile(const std::string& path, const std::string& contents,
+ const android::StringPiece& out_dir, IDiagnostics* diag) {
+ CHECK(WriteFile(path, contents));
+ CHECK(file::mkdirs(out_dir.data()));
+ return CompileCommand(diag).Execute({path, "-o", out_dir, "-v"}, &std::cerr) == 0;
+}
+
+bool CommandTestFixture::Link(const std::vector<std::string>& args,
+ const android::StringPiece& flat_dir, IDiagnostics* diag) {
+ std::vector<android::StringPiece> link_args;
+ for(const std::string& arg : args) {
+ link_args.emplace_back(arg);
+ }
+
+ // Link against the android SDK
+ std::string android_sdk = file::BuildPath({android::base::GetExecutableDirectory(),
+ "integration-tests", "CommandTests",
+ "android-28.jar"});
+ link_args.insert(link_args.end(), {"-I", android_sdk});
+
+ // Add the files from the compiled resources directory to the link file arguments
+ Maybe<std::vector<std::string>> compiled_files = file::FindFiles(flat_dir, diag);
+ if (compiled_files) {
+ for (std::string& compile_file : compiled_files.value()) {
+ compile_file = file::BuildPath({flat_dir, compile_file});
+ link_args.emplace_back(std::move(compile_file));
+ }
+ }
+
+ return LinkCommand(diag).Execute(link_args, &std::cerr) == 0;
+}
+
+std::string CommandTestFixture::GetDefaultManifest() {
+ const std::string manifest_file = GetTestPath("AndroidManifest.xml");
+ CHECK(WriteFile(manifest_file, R"(
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.aapt.command.test">
+ </manifest>)"));
+ return manifest_file;
+}
+
+void CommandTestFixture::AssertLoadXml(LoadedApk *apk, const android::StringPiece &xml_path,
+ android::ResXMLTree *out_tree) {
+ ASSERT_THAT(apk, Ne(nullptr));
+
+ io::IFile* file = apk->GetFileCollection()->FindFile(xml_path);
+ ASSERT_THAT(file, Ne(nullptr));
+
+ std::unique_ptr<io::IData> data = file->OpenAsData();
+ ASSERT_THAT(data, Ne(nullptr));
+
+ out_tree->setTo(data->data(), data->size());
+ ASSERT_THAT(out_tree->getError(), Eq(android::OK));
+ while (out_tree->next() != android::ResXMLTree::START_TAG) {
+ ASSERT_THAT(out_tree->getEventType(), Ne(android::ResXMLTree::BAD_DOCUMENT));
+ ASSERT_THAT(out_tree->getEventType(), Ne(android::ResXMLTree::END_DOCUMENT));
+ }
+}
+
+} // namespace aapt
\ No newline at end of file
diff --git a/tools/aapt2/test/Fixture.h b/tools/aapt2/test/Fixture.h
new file mode 100644
index 0000000..89d3b7b
--- /dev/null
+++ b/tools/aapt2/test/Fixture.h
@@ -0,0 +1,96 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef AAPT_TEST_FIXTURE_H
+#define AAPT_TEST_FIXTURE_H
+
+#include "android-base/file.h"
+#include "android-base/macros.h"
+#include "androidfw/StringPiece.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+#include "io/Util.h"
+#include "util/Files.h"
+#include "LoadedApk.h"
+
+namespace aapt {
+
+class TestDirectoryFixture : public ::testing::Test {
+ public:
+ TestDirectoryFixture() = default;
+ virtual ~TestDirectoryFixture() = default;
+
+ // Creates the test directory or clears its contents if it contains previously created files.
+ void SetUp() override;
+
+ // Clears the contents of the test directory.
+ void TearDown() override;
+
+ // Retrieve the test directory of the fixture.
+ const android::StringPiece GetTestDirectory() {
+ return temp_dir_;
+ }
+
+ // Retrieves the absolute path of the specified relative path in the test directory. Directories
+ // should be separated using forward slashes ('/'), and these slashes will be translated to
+ // backslashes when running Windows tests.
+ const std::string GetTestPath(const android::StringPiece& path) {
+ std::string base = temp_dir_;
+ for (android::StringPiece part : util::Split(path, '/')) {
+ file::AppendPath(&base, part);
+ }
+ return base;
+ }
+
+ // Creates a file with the specified contents, creates any intermediate directories in the
+ // process. The file path must be an absolute path within the test directory.
+ bool WriteFile(const std::string& path, const std::string& contents);
+
+ private:
+ std::string temp_dir_;
+ DISALLOW_COPY_AND_ASSIGN(TestDirectoryFixture);
+};
+
+class CommandTestFixture : public TestDirectoryFixture {
+ public:
+ CommandTestFixture() = default;
+ virtual ~CommandTestFixture() = default;
+
+ // Wries the contents of the file to the specified path. The file is compiled and the flattened
+ // file is written to the out directory.
+ bool CompileFile(const std::string& path, const std::string& contents,
+ const android::StringPiece& flat_out_dir, IDiagnostics* diag);
+
+ // Executes the link command with the specified arguments. The flattened files residing in the
+ // flat directory will be added to the link command as file arguments.
+ bool Link(const std::vector<std::string>& args, const android::StringPiece& flat_dir,
+ IDiagnostics* diag);
+
+ // Creates a minimal android manifest within the test directory and returns the file path.
+ std::string GetDefaultManifest();
+
+ // Asserts that loading the tree from the specified file in the apk succeeds.
+ void AssertLoadXml(LoadedApk* apk, const android::StringPiece& xml_path,
+ android::ResXMLTree* out_tree);
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(CommandTestFixture);
+};
+
+} // namespace aapt
+
+#endif // AAPT_TEST_FIXTURE_H
\ No newline at end of file
diff --git a/tools/aapt2/test/Test.h b/tools/aapt2/test/Test.h
index a24c01c..7d96d1f 100644
--- a/tools/aapt2/test/Test.h
+++ b/tools/aapt2/test/Test.h
@@ -23,5 +23,6 @@
#include "test/Builders.h"
#include "test/Common.h"
#include "test/Context.h"
+#include "test/Fixture.h"
#endif // AAPT_TEST_TEST_H
diff --git a/tools/aapt2/util/Files.cpp b/tools/aapt2/util/Files.cpp
index 5cfbbf2..7b268bb 100644
--- a/tools/aapt2/util/Files.cpp
+++ b/tools/aapt2/util/Files.cpp
@@ -180,6 +180,17 @@
base->append(part.data(), part.size());
}
+std::string BuildPath(std::vector<const StringPiece>&& args) {
+ if (args.empty()) {
+ return "";
+ }
+ std::string out = args[0].to_string();
+ for (int i = 1; i < args.size(); i++) {
+ file::AppendPath(&out, args[i]);
+ }
+ return out;
+}
+
std::string PackageToPath(const StringPiece& package) {
std::string out_path;
for (const StringPiece& part : util::Tokenize(package, '.')) {
diff --git a/tools/aapt2/util/Files.h b/tools/aapt2/util/Files.h
index 219e1a0..5839552 100644
--- a/tools/aapt2/util/Files.h
+++ b/tools/aapt2/util/Files.h
@@ -57,6 +57,9 @@
// Appends a path to `base`, separated by the directory separator.
void AppendPath(std::string* base, android::StringPiece part);
+// Concatenates the list of paths and separates each part with the directory separator.
+std::string BuildPath(std::vector<const android::StringPiece>&& args);
+
// Makes all the directories in `path`. The last element in the path is interpreted as a directory.
bool mkdirs(const std::string& path);
diff --git a/tools/aapt2/util/Maybe.h b/tools/aapt2/util/Maybe.h
index 031276c..047e1a5 100644
--- a/tools/aapt2/util/Maybe.h
+++ b/tools/aapt2/util/Maybe.h
@@ -44,12 +44,12 @@
Maybe(const Maybe& rhs);
template <typename U>
- Maybe(const Maybe<U>& rhs); // NOLINT(implicit)
+ Maybe(const Maybe<U>& rhs); // NOLINT(google-explicit-constructor)
Maybe(Maybe&& rhs) noexcept;
template <typename U>
- Maybe(Maybe<U>&& rhs); // NOLINT(implicit)
+ Maybe(Maybe<U>&& rhs); // NOLINT(google-explicit-constructor)
Maybe& operator=(const Maybe& rhs);
@@ -64,12 +64,12 @@
/**
* Construct a Maybe holding a value.
*/
- Maybe(const T& value); // NOLINT(implicit)
+ Maybe(const T& value); // NOLINT(google-explicit-constructor)
/**
* Construct a Maybe holding a value.
*/
- Maybe(T&& value); // NOLINT(implicit)
+ Maybe(T&& value); // NOLINT(google-explicit-constructor)
/**
* True if this holds a value, false if
diff --git a/wifi/java/android/net/wifi/aware/PeerHandle.java b/wifi/java/android/net/wifi/aware/PeerHandle.java
index 8ae4b5a..1603d00 100644
--- a/wifi/java/android/net/wifi/aware/PeerHandle.java
+++ b/wifi/java/android/net/wifi/aware/PeerHandle.java
@@ -16,6 +16,9 @@
package android.net.wifi.aware;
+import android.os.Parcel;
+import android.os.Parcelable;
+
/**
* Opaque object used to represent a Wi-Fi Aware peer. Obtained from discovery sessions in
* {@link DiscoverySessionCallback#onServiceDiscovered(PeerHandle, byte[], java.util.List)} or
@@ -33,7 +36,7 @@
* {@link PublishConfig.Builder#setServiceSpecificInfo(byte[])}, or match filter,
* {@link PublishConfig.Builder#setMatchFilter(java.util.List)}.
*/
-public class PeerHandle {
+public final class PeerHandle implements Parcelable {
/** @hide */
public PeerHandle(int peerId) {
this.peerId = peerId;
@@ -59,4 +62,29 @@
public int hashCode() {
return peerId;
}
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeInt(peerId);
+ }
+
+ public static final Creator<PeerHandle> CREATOR = new Creator<PeerHandle>() {
+ @Override
+ public PeerHandle[] newArray(int size) {
+ return new PeerHandle[size];
+ }
+
+ @Override
+ public PeerHandle createFromParcel(Parcel in) {
+ int peerHandle = in.readInt();
+
+ return new PeerHandle(peerHandle);
+ }
+ };
+
}
diff --git a/wifi/tests/src/android/net/wifi/aware/WifiAwareManagerTest.java b/wifi/tests/src/android/net/wifi/aware/WifiAwareManagerTest.java
index e882b6b..ed38c76 100644
--- a/wifi/tests/src/android/net/wifi/aware/WifiAwareManagerTest.java
+++ b/wifi/tests/src/android/net/wifi/aware/WifiAwareManagerTest.java
@@ -1382,4 +1382,24 @@
assertEquals(cap.getPeerIpv6Addr().toString(), "/fe80::1322:33ff:fe44:5566%5");
assertEquals(cap.hashCode(), rereadCap.hashCode());
}
+
+ // PeerHandle tests
+
+ @Test
+ public void testPeerHandleParcel() {
+ final PeerHandle peerHandle = new PeerHandle(5);
+
+ Parcel parcelW = Parcel.obtain();
+ peerHandle.writeToParcel(parcelW, 0);
+ byte[] bytes = parcelW.marshall();
+ parcelW.recycle();
+
+ Parcel parcelR = Parcel.obtain();
+ parcelR.unmarshall(bytes, 0, bytes.length);
+ parcelR.setDataPosition(0);
+ PeerHandle rereadPeerHandle = PeerHandle.CREATOR.createFromParcel(parcelR);
+
+ assertEquals(peerHandle, rereadPeerHandle);
+ assertEquals(peerHandle.hashCode(), rereadPeerHandle.hashCode());
+ }
}