diff options
author | TreeHugger Robot <treehugger-gerrit@google.com> | 2018-07-19 22:29:50 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2018-07-19 22:29:50 +0000 |
commit | 90ba1f1362aa255945c74c846553a9372bb40146 (patch) | |
tree | 9df94d802a55f8f16bb04a5c618ecc515141731d | |
parent | 98563bff3eead3f5a1a15e91db17d318c3d8dd96 (diff) | |
parent | cdee12016c0cae41ae68c8f44a70b8f6d1271603 (diff) | |
download | Car-pie-dr1-dev.tar.gz |
Merge "Provide an option to disable UxR change broadcast." into pi-devpie-dr1-dev
-rw-r--r-- | service/src/com/android/car/CarUxRestrictionsManagerService.java | 53 | ||||
-rw-r--r-- | service/src/com/android/car/pm/CarPackageManagerService.java | 12 |
2 files changed, 64 insertions, 1 deletions
diff --git a/service/src/com/android/car/CarUxRestrictionsManagerService.java b/service/src/com/android/car/CarUxRestrictionsManagerService.java index a6807d6a66..b90939b320 100644 --- a/service/src/com/android/car/CarUxRestrictionsManagerService.java +++ b/service/src/com/android/car/CarUxRestrictionsManagerService.java @@ -27,11 +27,17 @@ import android.car.hardware.CarPropertyValue; import android.car.hardware.property.CarPropertyEvent; import android.car.hardware.property.ICarPropertyEventListener; import android.content.Context; +import android.content.pm.PackageManager; import android.hardware.automotive.vehicle.V2_0.VehicleProperty; +import android.os.Binder; +import android.os.Build; import android.os.IBinder; +import android.os.Process; import android.os.RemoteException; import android.util.Log; +import com.android.internal.annotations.GuardedBy; + import org.xmlpull.v1.XmlPullParserException; import java.io.IOException; @@ -60,6 +66,9 @@ public class CarUxRestrictionsManagerService extends ICarUxRestrictionsManager.S private CarUxRestrictions mCurrentUxRestrictions; private float mCurrentMovingSpeed; private boolean mFallbackToDefaults; + // Flag to disable broadcasting UXR changes - for development purposes + @GuardedBy("this") + private boolean mUxRChangeBroadcastEnabled = true; // For dumpsys logging private final LinkedList<Utils.TransitionLog> mTransitionLogs = new LinkedList<>(); @@ -224,6 +233,42 @@ public class CarUxRestrictionsManagerService extends ICarUxRestrictionsManager.S } /** + * Enable/disable UX restrictions change broadcast blocking. + * Setting this to true will stop broadcasts of UX restriction change to listeners. + * This method works only on debug builds and the caller of this method needs to have the same + * signature of the car service. + * + */ + public synchronized void setUxRChangeBroadcastEnabled(boolean enable) { + if (!isDebugBuild()) { + Log.e(TAG, "Cannot set UX restriction change broadcast."); + return; + } + // Check if the caller has the same signature as that of the car service. + if (mContext.getPackageManager().checkSignatures(Process.myUid(), Binder.getCallingUid()) + != PackageManager.SIGNATURE_MATCH) { + throw new SecurityException( + "Caller " + mContext.getPackageManager().getNameForUid(Binder.getCallingUid()) + + " does not have the right signature"); + } + if (enable) { + // if enabling it back, send the current restrictions + mUxRChangeBroadcastEnabled = enable; + handleDispatchUxRestrictions(mDrivingStateService.getCurrentDrivingState().eventValue, + getCurrentSpeed()); + } else { + // fake parked state, so if the system is currently restricted, the restrictions are + // relaxed. + handleDispatchUxRestrictions(CarDrivingStateEvent.DRIVING_STATE_PARKED, 0); + mUxRChangeBroadcastEnabled = enable; + } + } + + private boolean isDebugBuild() { + return Build.IS_USERDEBUG || Build.IS_ENG; + } + + /** * Class that holds onto client related information - listener interface, process that hosts the * binder object etc. * It also registers for death notifications of the host. @@ -282,6 +327,9 @@ public class CarUxRestrictionsManagerService extends ICarUxRestrictionsManager.S writer.println( "Requires DO? " + mCurrentUxRestrictions.isRequiresDistractionOptimization()); writer.println("Current UXR: " + mCurrentUxRestrictions.getActiveRestrictions()); + if (isDebugBuild()) { + writer.println("mUxRChangeBroadcastEnabled? " + mUxRChangeBroadcastEnabled); + } mHelper.dump(writer); writer.println("UX Restriction change log:"); for (Utils.TransitionLog tlog : mTransitionLogs) { @@ -377,6 +425,11 @@ public class CarUxRestrictionsManagerService extends ICarUxRestrictionsManager.S */ private synchronized void handleDispatchUxRestrictions(@CarDrivingState int currentDrivingState, float speed) { + if (isDebugBuild() && !mUxRChangeBroadcastEnabled) { + Log.d(TAG, "Not dispatching UX Restriction due to setting"); + return; + } + CarUxRestrictions uxRestrictions; // Get UX restrictions from the parsed configuration XML or fall back to defaults if not // available. diff --git a/service/src/com/android/car/pm/CarPackageManagerService.java b/service/src/com/android/car/pm/CarPackageManagerService.java index 198066610e..ed51a78269 100644 --- a/service/src/com/android/car/pm/CarPackageManagerService.java +++ b/service/src/com/android/car/pm/CarPackageManagerService.java @@ -985,8 +985,18 @@ public class CarPackageManagerService extends ICarPackageManager.Stub implements } } + /** + * Enable/Disable activity blocking by correspondingly enabling/disabling broadcasting UXR + * changes in {@link CarUxRestrictionsManagerService}. This is only available in + * engineering builds for development convenience. + * + */ @Override public synchronized void setEnableActivityBlocking(boolean enable) { + if (!isDebugBuild()) { + Log.e(CarLog.TAG_PACKAGE, "Cannot enable/disable activity blocking"); + return; + } // Check if the caller has the same signature as that of the car service. if (mPackageManager.checkSignatures(Process.myUid(), Binder.getCallingUid()) != PackageManager.SIGNATURE_MATCH) { @@ -994,7 +1004,7 @@ public class CarPackageManagerService extends ICarPackageManager.Stub implements "Caller " + mPackageManager.getNameForUid(Binder.getCallingUid()) + " does not have the right signature"); } - mEnableActivityBlocking = enable; + mCarUxRestrictionsService.setUxRChangeBroadcastEnabled(enable); } /** |