Merge "Support ANRs from windows that are not tracked by WM" into tm-dev
diff --git a/ApiDocs.bp b/ApiDocs.bp
index 5b7c125..7f5d4a3 100644
--- a/ApiDocs.bp
+++ b/ApiDocs.bp
@@ -94,7 +94,7 @@
":framework-scheduling-sources",
":framework-sdkextensions-sources",
":framework-statsd-sources",
- ":framework-supplementalprocess-sources",
+ ":framework-sdksandbox-sources",
":framework-tethering-srcs",
":framework-uwb-updatable-sources",
":framework-wifi-updatable-sources",
diff --git a/apex/blobstore/service/java/com/android/server/blob/BlobStoreManagerService.java b/apex/blobstore/service/java/com/android/server/blob/BlobStoreManagerService.java
index ffa534e..c83ca8c 100644
--- a/apex/blobstore/service/java/com/android/server/blob/BlobStoreManagerService.java
+++ b/apex/blobstore/service/java/com/android/server/blob/BlobStoreManagerService.java
@@ -1377,7 +1377,7 @@
}
private boolean isAllowedBlobAccess(int uid, String packageName) {
- return (!Process.isSupplemental(uid) && !Process.isIsolated(uid)
+ return (!Process.isSdkSandboxUid(uid) && !Process.isIsolated(uid)
&& !mPackageManagerInternal.isInstantApp(packageName, UserHandle.getUserId(uid)));
}
diff --git a/api/Android.bp b/api/Android.bp
index 9e377a0..464c163 100644
--- a/api/Android.bp
+++ b/api/Android.bp
@@ -123,7 +123,7 @@
"framework-scheduling",
"framework-sdkextensions",
"framework-statsd",
- "framework-supplementalprocess",
+ "framework-sdksandbox",
"framework-tethering",
"framework-uwb",
"framework-wifi",
@@ -136,7 +136,7 @@
system_server_classpath: [
"service-media-s",
"service-permission",
- "service-supplementalprocess",
+ "service-sdksandbox",
],
}
diff --git a/cmds/incidentd/src/incidentd_util.cpp b/cmds/incidentd/src/incidentd_util.cpp
index 150ab99..ec0b79b 100644
--- a/cmds/incidentd/src/incidentd_util.cpp
+++ b/cmds/incidentd/src/incidentd_util.cpp
@@ -184,11 +184,26 @@
sigemptyset(&child_mask);
sigaddset(&child_mask, SIGCHLD);
+ // block SIGCHLD before we check if a process has exited
if (sigprocmask(SIG_BLOCK, &child_mask, &old_mask) == -1) {
- ALOGW("sigprocmask failed: %s", strerror(errno));
+ ALOGW("*** sigprocmask failed: %s\n", strerror(errno));
return false;
}
+ // if the child has exited already, handle and reset signals before leaving
+ pid_t child_pid = waitpid(pid, status, WNOHANG);
+ if (child_pid != pid) {
+ if (child_pid > 0) {
+ ALOGW("*** Waiting for pid %d, got pid %d instead\n", pid, child_pid);
+ sigprocmask(SIG_SETMASK, &old_mask, nullptr);
+ return false;
+ }
+ } else {
+ sigprocmask(SIG_SETMASK, &old_mask, nullptr);
+ return true;
+ }
+
+ // wait for a SIGCHLD
timespec ts;
ts.tv_sec = timeout_ms / 1000;
ts.tv_nsec = (timeout_ms % 1000) * 1000000;
@@ -197,7 +212,7 @@
// Set the signals back the way they were.
if (sigprocmask(SIG_SETMASK, &old_mask, nullptr) == -1) {
- ALOGW("sigprocmask failed: %s", strerror(errno));
+ ALOGW("*** sigprocmask failed: %s\n", strerror(errno));
if (ret == 0) {
return false;
}
@@ -207,21 +222,21 @@
if (errno == EAGAIN) {
errno = ETIMEDOUT;
} else {
- ALOGW("sigtimedwait failed: %s", strerror(errno));
+ ALOGW("*** sigtimedwait failed: %s\n", strerror(errno));
}
return false;
}
- pid_t child_pid = waitpid(pid, status, WNOHANG);
- if (child_pid == pid) {
- return true;
+ child_pid = waitpid(pid, status, WNOHANG);
+ if (child_pid != pid) {
+ if (child_pid != -1) {
+ ALOGW("*** Waiting for pid %d, got pid %d instead\n", pid, child_pid);
+ } else {
+ ALOGW("*** waitpid failed: %s\n", strerror(errno));
+ }
+ return false;
}
- if (child_pid == -1) {
- ALOGW("waitpid failed: %s", strerror(errno));
- } else {
- ALOGW("Waiting for pid %d, got pid %d instead", pid, child_pid);
- }
- return false;
+ return true;
}
status_t kill_child(pid_t pid) {
diff --git a/cmds/svc/src/com/android/commands/svc/BluetoothCommand.java b/cmds/svc/src/com/android/commands/svc/BluetoothCommand.java
deleted file mode 100644
index b572ce2..0000000
--- a/cmds/svc/src/com/android/commands/svc/BluetoothCommand.java
+++ /dev/null
@@ -1,58 +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.commands.svc;
-
-import android.bluetooth.BluetoothAdapter;
-import android.os.RemoteException;
-
-public class BluetoothCommand extends Svc.Command {
-
- public BluetoothCommand() {
- super("bluetooth");
- }
-
- @Override
- public String shortHelp() {
- return "Control Bluetooth service";
- }
-
- @Override
- public String longHelp() {
- return shortHelp() + "\n"
- + "\n"
- + "usage: svc bluetooth [enable|disable]\n"
- + " Turn Bluetooth on or off.\n\n";
- }
-
- @Override
- public void run(String[] args) {
- BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
-
- if (adapter == null) {
- System.err.println("Got a null BluetoothAdapter, is the system running?");
- return;
- }
-
- if (args.length == 2 && "enable".equals(args[1])) {
- adapter.enable();
- } else if (args.length == 2 && "disable".equals(args[1])) {
- adapter.disable();
- } else {
- System.err.println(longHelp());
- }
- }
-}
diff --git a/cmds/svc/src/com/android/commands/svc/Svc.java b/cmds/svc/src/com/android/commands/svc/Svc.java
index 2ed2678..bbad984 100644
--- a/cmds/svc/src/com/android/commands/svc/Svc.java
+++ b/cmds/svc/src/com/android/commands/svc/Svc.java
@@ -96,7 +96,7 @@
// `svc wifi` has been migrated to WifiShellCommand
new UsbCommand(),
new NfcCommand(),
- new BluetoothCommand(),
+ // `svc bluetooth` has been migrated to BluetoothShellCommand
new SystemServerCommand(),
};
}
diff --git a/cmds/svc/svc b/cmds/svc/svc
index 95265e8..a2c9de3 100755
--- a/cmds/svc/svc
+++ b/cmds/svc/svc
@@ -33,6 +33,25 @@
exit 1
fi
+# `svc bluetooth` has been migrated to BluetoothShellCommand,
+# simply perform translation to `cmd bluetooth set-bluetooth-enabled` here.
+if [ "x$1" == "xbluetooth" ]; then
+ # `cmd wifi` by convention uses enabled/disabled
+ # instead of enable/disable
+ if [ "x$2" == "xenable" ]; then
+ exec cmd bluetooth_manager enable
+ elif [ "x$2" == "xdisable" ]; then
+ exec cmd bluetooth_manager disable
+ else
+ echo "Control the Bluetooth manager"
+ echo ""
+ echo "usage: svc bluetooth [enable|disable]"
+ echo " Turn Bluetooth on or off."
+ echo ""
+ fi
+ exit 1
+fi
+
export CLASSPATH=/system/framework/svc.jar
exec app_process /system/bin com.android.commands.svc.Svc "$@"
diff --git a/core/api/current.txt b/core/api/current.txt
index e695cf6..cd0bd86 100644
--- a/core/api/current.txt
+++ b/core/api/current.txt
@@ -7388,8 +7388,8 @@
method public int getCurrentFailedPasswordAttempts();
method @Nullable public java.util.List<java.lang.String> getDelegatePackages(@NonNull android.content.ComponentName, @NonNull String);
method @NonNull public java.util.List<java.lang.String> getDelegatedScopes(@Nullable android.content.ComponentName, @NonNull String);
- method @Nullable public String getDeviceManagerRoleHolderPackageName();
method public CharSequence getDeviceOwnerLockScreenInfo();
+ method @Nullable public String getDevicePolicyManagementRoleHolderPackage();
method @Nullable public android.graphics.drawable.Drawable getDrawable(@NonNull String, @NonNull String, @NonNull java.util.function.Supplier<android.graphics.drawable.Drawable>);
method @Nullable public android.graphics.drawable.Drawable getDrawable(@NonNull String, @NonNull String, @NonNull String, @NonNull java.util.function.Supplier<android.graphics.drawable.Drawable>);
method @Nullable public android.graphics.drawable.Icon getDrawableAsIcon(@NonNull String, @NonNull String, @NonNull String, @Nullable android.graphics.drawable.Icon);
@@ -31858,7 +31858,7 @@
method public static final boolean is64Bit();
method public static boolean isApplicationUid(int);
method public static final boolean isIsolated();
- method public static final boolean isSupplemental();
+ method public static final boolean isSdkSandbox();
method public static final void killProcess(int);
method public static final int myPid();
method @NonNull public static String myProcessName();
@@ -38080,6 +38080,7 @@
}
public final class Field {
+ method @Nullable public java.util.regex.Pattern getFilter();
method @Nullable public android.service.autofill.Presentations getPresentations();
method @Nullable public android.view.autofill.AutofillValue getValue();
}
@@ -40753,8 +40754,9 @@
method public String getDefaultDialerPackage();
method @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public android.telecom.PhoneAccountHandle getDefaultOutgoingPhoneAccount(String);
method @Deprecated @RequiresPermission(anyOf={android.Manifest.permission.READ_PHONE_STATE, android.Manifest.permission.READ_SMS, android.Manifest.permission.READ_PHONE_NUMBERS}, conditional=true) public String getLine1Number(android.telecom.PhoneAccountHandle);
+ method @NonNull @RequiresPermission(android.Manifest.permission.MANAGE_OWN_CALLS) public java.util.List<android.telecom.PhoneAccountHandle> getOwnSelfManagedPhoneAccounts();
method public android.telecom.PhoneAccount getPhoneAccount(android.telecom.PhoneAccountHandle);
- method @RequiresPermission(anyOf={"android.permission.READ_PRIVILEGED_PHONE_STATE", android.Manifest.permission.READ_PHONE_STATE, android.Manifest.permission.MANAGE_OWN_CALLS}) public java.util.List<android.telecom.PhoneAccountHandle> getSelfManagedPhoneAccounts();
+ method @NonNull @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public java.util.List<android.telecom.PhoneAccountHandle> getSelfManagedPhoneAccounts();
method public android.telecom.PhoneAccountHandle getSimCallManager();
method @Nullable public android.telecom.PhoneAccountHandle getSimCallManagerForSubscription(int);
method @Nullable public String getSystemDialerPackage();
diff --git a/core/api/module-lib-current.txt b/core/api/module-lib-current.txt
index 7ec239d..a268f85 100644
--- a/core/api/module-lib-current.txt
+++ b/core/api/module-lib-current.txt
@@ -120,7 +120,7 @@
public abstract class PackageManager {
method @NonNull public String getPermissionControllerPackageName();
- method @NonNull public String getSupplementalProcessPackageName();
+ method @NonNull public String getSdkSandboxPackageName();
field public static final int MATCH_STATIC_SHARED_AND_SDK_LIBRARIES = 67108864; // 0x4000000
}
@@ -362,9 +362,9 @@
}
public class Process {
- method public static final boolean isSupplemental(int);
+ method public static final boolean isSdkSandboxUid(int);
method public static final int toAppUid(int);
- method public static final int toSupplementalUid(int);
+ method public static final int toSdkSandboxUid(int);
field public static final int NFC_UID = 1027; // 0x403
field public static final int VPN_UID = 1016; // 0x3f8
}
diff --git a/core/api/system-current.txt b/core/api/system-current.txt
index e611d6b..e34498736 100644
--- a/core/api/system-current.txt
+++ b/core/api/system-current.txt
@@ -416,7 +416,7 @@
field public static final int config_defaultCallScreening = 17039398; // 0x1040026
field public static final int config_defaultDialer = 17039395; // 0x1040023
field public static final int config_defaultSms = 17039396; // 0x1040024
- field public static final int config_deviceManager;
+ field public static final int config_devicePolicyManagement;
field public static final int config_feedbackIntentExtraKey = 17039391; // 0x104001f
field public static final int config_feedbackIntentNameKey = 17039392; // 0x1040020
field public static final int config_helpIntentExtraKey = 17039389; // 0x104001d
diff --git a/core/api/test-current.txt b/core/api/test-current.txt
index 22637ca..ed18a22 100644
--- a/core/api/test-current.txt
+++ b/core/api/test-current.txt
@@ -155,8 +155,10 @@
public class ActivityOptions {
method @NonNull public static android.app.ActivityOptions fromBundle(@NonNull android.os.Bundle);
+ method public boolean isEligibleForLegacyPermissionPrompt();
method @NonNull public static android.app.ActivityOptions makeCustomAnimation(@NonNull android.content.Context, int, int, int, @Nullable android.os.Handler, @Nullable android.app.ActivityOptions.OnAnimationStartedListener, @Nullable android.app.ActivityOptions.OnAnimationFinishedListener);
method @NonNull @RequiresPermission(android.Manifest.permission.START_TASKS_FROM_RECENTS) public static android.app.ActivityOptions makeCustomTaskAnimation(@NonNull android.content.Context, int, int, @Nullable android.os.Handler, @Nullable android.app.ActivityOptions.OnAnimationStartedListener, @Nullable android.app.ActivityOptions.OnAnimationFinishedListener);
+ method public void setEligibleForLegacyPermissionPrompt(boolean);
method public static void setExitTransitionTimeout(long);
method public void setLaunchActivityType(int);
method public void setLaunchWindowingMode(int);
@@ -826,9 +828,9 @@
method @NonNull public java.util.List<android.content.pm.ApplicationInfo> getInstalledApplicationsAsUser(@NonNull android.content.pm.PackageManager.ApplicationInfoFlags, int);
method @Nullable public abstract String[] getNamesForUids(int[]);
method @NonNull public String getPermissionControllerPackageName();
+ method @NonNull public String getSdkSandboxPackageName();
method @NonNull public abstract String getServicesSystemSharedLibraryPackageName();
method @NonNull public abstract String getSharedSystemSharedLibraryPackageName();
- method @NonNull public String getSupplementalProcessPackageName();
method @Nullable public String getSystemTextClassifierPackageName();
method @Nullable public String getWellbeingPackageName();
method public void holdLock(android.os.IBinder, int);
@@ -1774,7 +1776,7 @@
public class Process {
method public static final int getThreadScheduler(int) throws java.lang.IllegalArgumentException;
- method public static final int toSupplementalUid(int);
+ method public static final int toSdkSandboxUid(int);
field public static final int FIRST_APP_ZYGOTE_ISOLATED_UID = 90000; // 0x15f90
field public static final int FIRST_ISOLATED_UID = 99000; // 0x182b8
field public static final int LAST_APP_ZYGOTE_ISOLATED_UID = 98999; // 0x182b7
diff --git a/core/java/android/app/ActivityOptions.java b/core/java/android/app/ActivityOptions.java
index 5ddaa80..1d14307 100644
--- a/core/java/android/app/ActivityOptions.java
+++ b/core/java/android/app/ActivityOptions.java
@@ -174,6 +174,13 @@
public static final String KEY_SPLASH_SCREEN_THEME = "android.activity.splashScreenTheme";
/**
+ * Indicates that this activity launch is eligible to show a legacy permission prompt
+ * @hide
+ */
+ public static final String KEY_LEGACY_PERMISSION_PROMPT_ELIGIBLE =
+ "android:activity.legacyPermissionPromptEligible";
+
+ /**
* Callback for when the last frame of the animation is played.
* @hide
*/
@@ -445,6 +452,7 @@
private String mSplashScreenThemeResName;
@SplashScreen.SplashScreenStyle
private int mSplashScreenStyle = SplashScreen.SPLASH_SCREEN_STYLE_UNDEFINED;
+ private boolean mIsEligibleForLegacyPermissionPrompt;
private boolean mRemoveWithTaskOrganizer;
private boolean mLaunchedFromBubble;
private boolean mTransientLaunch;
@@ -1243,6 +1251,8 @@
mTransientLaunch = opts.getBoolean(KEY_TRANSIENT_LAUNCH);
mSplashScreenStyle = opts.getInt(KEY_SPLASH_SCREEN_STYLE);
mLaunchIntoPipParams = opts.getParcelable(KEY_LAUNCH_INTO_PIP_PARAMS);
+ mIsEligibleForLegacyPermissionPrompt =
+ opts.getBoolean(KEY_LEGACY_PERMISSION_PROMPT_ELIGIBLE);
}
/**
@@ -1474,6 +1484,24 @@
}
/**
+ * Whether the activity is eligible to show a legacy permission prompt
+ * @hide
+ */
+ @TestApi
+ public boolean isEligibleForLegacyPermissionPrompt() {
+ return mIsEligibleForLegacyPermissionPrompt;
+ }
+
+ /**
+ * Sets whether the activity is eligible to show a legacy permission prompt
+ * @hide
+ */
+ @TestApi
+ public void setEligibleForLegacyPermissionPrompt(boolean eligible) {
+ mIsEligibleForLegacyPermissionPrompt = eligible;
+ }
+
+ /**
* Sets whether the activity is to be launched into LockTask mode.
*
* Use this option to start an activity in LockTask mode. Note that only apps permitted by
@@ -1909,6 +1937,7 @@
mSpecsFuture = otherOptions.mSpecsFuture;
mRemoteAnimationAdapter = otherOptions.mRemoteAnimationAdapter;
mLaunchIntoPipParams = otherOptions.mLaunchIntoPipParams;
+ mIsEligibleForLegacyPermissionPrompt = otherOptions.mIsEligibleForLegacyPermissionPrompt;
}
/**
@@ -2084,6 +2113,10 @@
if (mLaunchIntoPipParams != null) {
b.putParcelable(KEY_LAUNCH_INTO_PIP_PARAMS, mLaunchIntoPipParams);
}
+ if (mIsEligibleForLegacyPermissionPrompt) {
+ b.putBoolean(KEY_LEGACY_PERMISSION_PROMPT_ELIGIBLE,
+ mIsEligibleForLegacyPermissionPrompt);
+ }
return b;
}
diff --git a/core/java/android/app/ApplicationPackageManager.java b/core/java/android/app/ApplicationPackageManager.java
index 20ffa25..bda2e45 100644
--- a/core/java/android/app/ApplicationPackageManager.java
+++ b/core/java/android/app/ApplicationPackageManager.java
@@ -867,9 +867,9 @@
* @hide
*/
@Override
- public String getSupplementalProcessPackageName() {
+ public String getSdkSandboxPackageName() {
try {
- return mPM.getSupplementalProcessPackageName();
+ return mPM.getSdkSandboxPackageName();
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
diff --git a/core/java/android/app/KeyguardManager.java b/core/java/android/app/KeyguardManager.java
index 87ba197..cedf483e 100644
--- a/core/java/android/app/KeyguardManager.java
+++ b/core/java/android/app/KeyguardManager.java
@@ -184,8 +184,17 @@
})
@interface LockTypes {}
- // TODO(b/220379118): register only one binder listener and keep a map of listener to executor.
- private final ArrayMap<KeyguardLockedStateListener, IKeyguardLockedStateListener>
+ private final IKeyguardLockedStateListener mIKeyguardLockedStateListener =
+ new IKeyguardLockedStateListener.Stub() {
+ @Override
+ public void onKeyguardLockedStateChanged(boolean isKeyguardLocked) {
+ mKeyguardLockedStateListeners.forEach((listener, executor) -> {
+ executor.execute(
+ () -> listener.onKeyguardLockedStateChanged(isKeyguardLocked));
+ });
+ }
+ };
+ private final ArrayMap<KeyguardLockedStateListener, Executor>
mKeyguardLockedStateListeners = new ArrayMap<>();
/**
@@ -1102,17 +1111,12 @@
public void addKeyguardLockedStateListener(@NonNull @CallbackExecutor Executor executor,
@NonNull KeyguardLockedStateListener listener) {
synchronized (mKeyguardLockedStateListeners) {
+ mKeyguardLockedStateListeners.put(listener, executor);
+ if (mKeyguardLockedStateListeners.size() > 1) {
+ return;
+ }
try {
- final IKeyguardLockedStateListener innerListener =
- new IKeyguardLockedStateListener.Stub() {
- @Override
- public void onKeyguardLockedStateChanged(boolean isKeyguardLocked) {
- executor.execute(
- () -> listener.onKeyguardLockedStateChanged(isKeyguardLocked));
- }
- };
- mWM.addKeyguardLockedStateListener(innerListener);
- mKeyguardLockedStateListeners.put(listener, innerListener);
+ mWM.addKeyguardLockedStateListener(mIKeyguardLockedStateListener);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
@@ -1125,17 +1129,15 @@
@RequiresPermission(Manifest.permission.SUBSCRIBE_TO_KEYGUARD_LOCKED_STATE)
public void removeKeyguardLockedStateListener(@NonNull KeyguardLockedStateListener listener) {
synchronized (mKeyguardLockedStateListeners) {
- IKeyguardLockedStateListener innerListener = mKeyguardLockedStateListeners.get(
- listener);
- if (innerListener == null) {
+ mKeyguardLockedStateListeners.remove(listener);
+ if (!mKeyguardLockedStateListeners.isEmpty()) {
return;
}
try {
- mWM.removeKeyguardLockedStateListener(innerListener);
+ mWM.removeKeyguardLockedStateListener(mIKeyguardLockedStateListener);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
- mKeyguardLockedStateListeners.remove(listener);
}
}
}
diff --git a/core/java/android/app/SystemServiceRegistry.java b/core/java/android/app/SystemServiceRegistry.java
index eeb4705..ddce29d 100644
--- a/core/java/android/app/SystemServiceRegistry.java
+++ b/core/java/android/app/SystemServiceRegistry.java
@@ -36,6 +36,7 @@
import android.app.people.PeopleManager;
import android.app.prediction.AppPredictionManager;
import android.app.role.RoleFrameworkInitializer;
+import android.app.sdksandbox.SdkSandboxManagerFrameworkInitializer;
import android.app.search.SearchUiManager;
import android.app.slice.SliceManager;
import android.app.smartspace.SmartspaceManager;
@@ -208,7 +209,6 @@
import android.service.persistentdata.IPersistentDataBlockService;
import android.service.persistentdata.PersistentDataBlockManager;
import android.service.vr.IVrManager;
-import android.supplementalprocess.SupplementalProcessFrameworkInitializer;
import android.telecom.TelecomManager;
import android.telephony.MmsManager;
import android.telephony.TelephonyFrameworkInitializer;
@@ -1564,7 +1564,7 @@
MediaFrameworkInitializer.registerServiceWrappers();
RoleFrameworkInitializer.registerServiceWrappers();
SchedulingFrameworkInitializer.registerServiceWrappers();
- SupplementalProcessFrameworkInitializer.registerServiceWrappers();
+ SdkSandboxManagerFrameworkInitializer.registerServiceWrappers();
UwbFrameworkInitializer.registerServiceWrappers();
SafetyCenterFrameworkInitializer.registerServiceWrappers();
ConnectivityFrameworkInitializerTiramisu.registerServiceWrappers();
diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java
index b944468..d5d14c6 100644
--- a/core/java/android/app/admin/DevicePolicyManager.java
+++ b/core/java/android/app/admin/DevicePolicyManager.java
@@ -545,15 +545,16 @@
= "android.app.action.PROVISION_FINALIZATION";
/**
- * Activity action: starts the managed profile provisioning flow inside the device management
- * role holder.
+ * Activity action: starts the managed profile provisioning flow inside the device policy
+ * management role holder.
*
* <p>During the managed profile provisioning flow, the platform-provided provisioning handler
- * will delegate provisioning to the device management role holder, by firing this intent.
- * Third-party mobile device management applications attempting to fire this intent will
+ * will delegate provisioning to the device policy management role holder, by firing this
+ * intent. Third-party mobile device management applications attempting to fire this intent will
* receive a {@link SecurityException}.
*
- * <p>Device management role holders are required to have a handler for this intent action.
+ * <p>Device policy management role holders are required to have a handler for this intent
+ * action.
*
* <p>If {@link #EXTRA_ROLE_HOLDER_STATE} is supplied to this intent, it is the responsibility
* of the role holder to restore its state from this extra. This is the same {@link Bundle}
@@ -596,15 +597,16 @@
public static final int RESULT_DEVICE_OWNER_SET = 123;
/**
- * Activity action: starts the trusted source provisioning flow inside the device management
- * role holder.
+ * Activity action: starts the trusted source provisioning flow inside the device policy
+ * management role holder.
*
* <p>During the trusted source provisioning flow, the platform-provided provisioning handler
- * will delegate provisioning to the device management role holder, by firing this intent.
- * Third-party mobile device management applications attempting to fire this intent will
+ * will delegate provisioning to the device policy management role holder, by firing this
+ * intent. Third-party mobile device management applications attempting to fire this intent will
* receive a {@link SecurityException}.
*
- * <p>Device management role holders are required to have a handler for this intent action.
+ * <p>Device policy management role holders are required to have a handler for this intent
+ * action.
*
* <p>If {@link #EXTRA_ROLE_HOLDER_STATE} is supplied to this intent, it is the responsibility
* of the role holder to restore its state from this extra. This is the same {@link Bundle}
@@ -624,15 +626,16 @@
"android.app.action.ROLE_HOLDER_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE";
/**
- * Activity action: starts the provisioning finalization flow inside the device management
- * role holder.
+ * Activity action: starts the provisioning finalization flow inside the device policy
+ * management role holder.
*
* <p>During the provisioning finalization flow, the platform-provided provisioning handler
- * will delegate provisioning to the device management role holder, by firing this intent.
- * Third-party mobile device management applications attempting to fire this intent will
+ * will delegate provisioning to the device policy management role holder, by firing this
+ * intent. Third-party mobile device management applications attempting to fire this intent will
* receive a {@link SecurityException}.
*
- * <p>Device management role holders are required to have a handler for this intent action.
+ * <p>Device policy management role holders are required to have a handler for this intent
+ * action.
*
* <p>This handler forwards the result from the admin app's {@link
* #ACTION_ADMIN_POLICY_COMPLIANCE} handler. Result code {@link Activity#RESULT_CANCELED}
@@ -697,9 +700,9 @@
* A boolean extra indicating whether offline provisioning is allowed.
*
* <p>For the online provisioning flow, there will be an attempt to download and install
- * the latest version of the device management role holder. The platform will then delegate
- * provisioning to the device management role holder via role holder-specific provisioning
- * actions.
+ * the latest version of the device policy management role holder. The platform will then
+ * delegate provisioning to the device policy management role holder via role holder-specific
+ * provisioning actions.
*
* <p>For the offline provisioning flow, the provisioning flow will always be handled by
* the platform.
@@ -720,8 +723,8 @@
"android.app.extra.PROVISIONING_ALLOW_OFFLINE";
/**
- * A String extra holding a url that specifies the download location of the device manager
- * role holder package.
+ * A String extra holding a url that specifies the download location of the device policy
+ * management role holder package.
*
* <p>This is only meant to be used in cases when a specific variant of the role holder package
* is needed (such as a debug variant). If not provided, the default variant of the device
@@ -777,13 +780,13 @@
/**
* An extra of type {@link android.os.PersistableBundle} that allows the provisioning initiator
- * to pass data to the device manager role holder.
+ * to pass data to the device policy management role holder.
*
- * <p>The device manager role holder will receive this extra via the {@link
+ * <p>The device policy management role holder will receive this extra via the {@link
* #ACTION_ROLE_HOLDER_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE} intent.
*
* <p>The contents of this extra are up to the contract between the provisioning initiator
- * and the device manager role holder.
+ * and the device policy management role holder.
*
* <p>Use in an intent with action {@link #ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE}
* or in an NFC record with {@link #MIME_TYPE_PROVISIONING_NFC} that starts device owner
@@ -814,18 +817,19 @@
* <p>If {@link #EXTRA_PROVISIONING_SHOULD_LAUNCH_RESULT_INTENT} is set to {@code false},
* this result will be supplied as part of the result {@link Intent} for provisioning actions
* such as {@link #ACTION_PROVISION_MANAGED_PROFILE}. This result will also be supplied as
- * part of the result {@link Intent} for the device manager role holder provisioning actions.
+ * part of the result {@link Intent} for the device policy management role holder provisioning
+ * actions.
*/
public static final String EXTRA_RESULT_LAUNCH_INTENT =
"android.app.extra.RESULT_LAUNCH_INTENT";
/**
* A boolean extra that determines whether the provisioning flow should launch the resulting
- * launch intent, if one is supplied by the device manager role holder via {@link
+ * launch intent, if one is supplied by the device policy management role holder via {@link
* #EXTRA_RESULT_LAUNCH_INTENT}. Default value is {@code false}.
*
* <p>If {@code true}, the resulting intent will be launched by the provisioning flow, if one
- * is supplied by the device manager role holder.
+ * is supplied by the device policy management role holder.
*
* <p>If {@code false}, the resulting intent will be returned as {@link
* #EXTRA_RESULT_LAUNCH_INTENT} to the provisioning initiator, if one is supplied by the device
@@ -3220,10 +3224,10 @@
"android.app.action.ADMIN_POLICY_COMPLIANCE";
/**
- * Activity action: Starts the device management role holder updater.
+ * Activity action: Starts the device policy management role holder updater.
*
- * <p>The activity must handle the device management role holder update and set the intent
- * result to either {@link Activity#RESULT_OK} if the update was successful, {@link
+ * <p>The activity must handle the device policy management role holder update and set the
+ * intent result to either {@link Activity#RESULT_OK} if the update was successful, {@link
* #RESULT_UPDATE_DEVICE_MANAGEMENT_ROLE_HOLDER_RECOVERABLE_ERROR} if it encounters a problem
* that may be solved by relaunching it again, or {@link
* #RESULT_UPDATE_DEVICE_MANAGEMENT_ROLE_HOLDER_UNRECOVERABLE_ERROR} if it encounters a problem
@@ -3261,9 +3265,9 @@
/**
* An {@link Intent} extra which resolves to a custom user consent screen.
*
- * <p>If this extra is provided to the device management role holder via either {@link
+ * <p>If this extra is provided to the device policy management role holder via either {@link
* #ACTION_ROLE_HOLDER_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE} or {@link
- * #ACTION_ROLE_HOLDER_PROVISION_MANAGED_PROFILE}, the device management role holder must
+ * #ACTION_ROLE_HOLDER_PROVISION_MANAGED_PROFILE}, the device policy management role holder must
* launch this intent which shows the custom user consent screen, replacing its own standard
* consent screen.
*
@@ -3279,9 +3283,9 @@
* </ul>
*
* <p>If the custom consent screens are granted by the user {@link Activity#RESULT_OK} is
- * returned, otherwise {@link Activity#RESULT_CANCELED} is returned. The device management
- * role holder should ensure that the provisioning flow terminates immediately if consent
- * is not granted by the user.
+ * returned, otherwise {@link Activity#RESULT_CANCELED} is returned. The device policy
+ * management role holder should ensure that the provisioning flow terminates immediately if
+ * consent is not granted by the user.
*
* @hide
*/
@@ -15647,14 +15651,15 @@
}
/**
- * Returns the package name of the device manager role holder.
+ * Returns the package name of the device policy management role holder.
*
- * <p>If the device manager role holder is not configured for this device, returns {@code null}.
+ * <p>If the device policy management role holder is not configured for this device, returns
+ * {@code null}.
*/
@Nullable
- public String getDeviceManagerRoleHolderPackageName() {
- String deviceManagerConfig =
- mContext.getString(com.android.internal.R.string.config_deviceManager);
+ public String getDevicePolicyManagementRoleHolderPackage() {
+ String deviceManagerConfig = mContext.getString(
+ com.android.internal.R.string.config_devicePolicyManagement);
return extractPackageNameFromDeviceManagerConfig(deviceManagerConfig);
}
diff --git a/core/java/android/content/pm/IPackageManager.aidl b/core/java/android/content/pm/IPackageManager.aidl
index 30aed8b..e9e6cd3 100644
--- a/core/java/android/content/pm/IPackageManager.aidl
+++ b/core/java/android/content/pm/IPackageManager.aidl
@@ -653,7 +653,7 @@
@UnsupportedAppUsage(maxTargetSdk = 30, trackingBug = 170729553)
String getPermissionControllerPackageName();
- String getSupplementalProcessPackageName();
+ String getSdkSandboxPackageName();
ParceledListSlice getInstantApps(int userId);
byte[] getInstantAppCookie(String packageName, int userId);
diff --git a/core/java/android/content/pm/PackageManager.java b/core/java/android/content/pm/PackageManager.java
index a162c41..f4bc161 100644
--- a/core/java/android/content/pm/PackageManager.java
+++ b/core/java/android/content/pm/PackageManager.java
@@ -5772,16 +5772,16 @@
}
/**
- * Returns the package name of the component implementing supplemental process service.
+ * Returns the package name of the component implementing sdk sandbox service.
*
- * @return the package name of the component implementing supplemental process service
+ * @return the package name of the component implementing sdk sandbox service
*
* @hide
*/
@NonNull
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
@TestApi
- public String getSupplementalProcessPackageName() {
+ public String getSdkSandboxPackageName() {
throw new RuntimeException("Not implemented. Must override in a subclass.");
}
diff --git a/core/java/android/os/Environment.java b/core/java/android/os/Environment.java
index 3d12941..79fa4fb 100644
--- a/core/java/android/os/Environment.java
+++ b/core/java/android/os/Environment.java
@@ -29,7 +29,6 @@
import android.compat.annotation.Disabled;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.Context;
-import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.storage.StorageManager;
@@ -1333,7 +1332,7 @@
final Context context = AppGlobals.getInitialApplication();
final int uid = context.getApplicationInfo().uid;
// Isolated processes and Instant apps are never allowed to be in scoped storage
- if (Process.isIsolated(uid) || Process.isSupplemental(uid)) {
+ if (Process.isIsolated(uid) || Process.isSdkSandboxUid(uid)) {
return false;
}
diff --git a/core/java/android/os/OWNERS b/core/java/android/os/OWNERS
index 5d9f2189..8e5ed8f 100644
--- a/core/java/android/os/OWNERS
+++ b/core/java/android/os/OWNERS
@@ -52,6 +52,9 @@
per-file *Telephony* = file:/telephony/OWNERS
per-file *Zygote* = file:/ZYGOTE_OWNERS
+# Time
+per-file *Clock* = file:/services/core/java/com/android/server/timezonedetector/OWNERS
+
# RecoverySystem
per-file *Recovery* = file:/services/core/java/com/android/server/recoverysystem/OWNERS
diff --git a/core/java/android/os/Process.java b/core/java/android/os/Process.java
index 17b5ec5..f069158c 100644
--- a/core/java/android/os/Process.java
+++ b/core/java/android/os/Process.java
@@ -281,23 +281,23 @@
/**
* Defines the start of a range of UIDs going from this number to
- * {@link #LAST_SUPPLEMENTAL_UID} that are reserved for assigning to
- * supplemental processes. There is a 1-1 mapping between a supplemental
+ * {@link #LAST_SDK_SANDBOX_UID} that are reserved for assigning to
+ * sdk sandbox processes. There is a 1-1 mapping between a sdk sandbox
* process UID and the app that it belongs to, which can be computed by
- * subtracting (FIRST_SUPPLEMENTAL_UID - FIRST_APPLICATION_UID) from the
- * uid of a supplemental process.
+ * subtracting (FIRST_SDK_SANDBOX_UID - FIRST_APPLICATION_UID) from the
+ * uid of a sdk sandbox process.
*
* Note that there are no GIDs associated with these processes; storage
* attribution for them will be done using project IDs.
* @hide
*/
- public static final int FIRST_SUPPLEMENTAL_UID = 20000;
+ public static final int FIRST_SDK_SANDBOX_UID = 20000;
/**
- * Last UID that is used for supplemental processes.
+ * Last UID that is used for sdk sandbox processes.
* @hide
*/
- public static final int LAST_SUPPLEMENTAL_UID = 29999;
+ public static final int LAST_SDK_SANDBOX_UID = 29999;
/**
* First uid used for fully isolated sandboxed processes spawned from an app zygote
@@ -901,44 +901,44 @@
}
/**
- * Returns whether the provided UID belongs to a supplemental process.
+ * Returns whether the provided UID belongs to a SDK sandbox process.
*
* @hide
*/
@SystemApi(client = MODULE_LIBRARIES)
- public static final boolean isSupplemental(int uid) {
+ public static final boolean isSdkSandboxUid(int uid) {
uid = UserHandle.getAppId(uid);
- return (uid >= FIRST_SUPPLEMENTAL_UID && uid <= LAST_SUPPLEMENTAL_UID);
+ return (uid >= FIRST_SDK_SANDBOX_UID && uid <= LAST_SDK_SANDBOX_UID);
}
/**
*
- * Returns the app process corresponding to a supplemental process.
+ * Returns the app process corresponding to a sdk sandbox process.
*
* @hide
*/
@SystemApi(client = MODULE_LIBRARIES)
public static final int toAppUid(int uid) {
- return uid - (FIRST_SUPPLEMENTAL_UID - FIRST_APPLICATION_UID);
+ return uid - (FIRST_SDK_SANDBOX_UID - FIRST_APPLICATION_UID);
}
/**
*
- * Returns the supplemental process corresponding to an app process.
+ * Returns the sdk sandbox process corresponding to an app process.
*
* @hide
*/
@SystemApi(client = MODULE_LIBRARIES)
@TestApi
- public static final int toSupplementalUid(int uid) {
- return uid + (FIRST_SUPPLEMENTAL_UID - FIRST_APPLICATION_UID);
+ public static final int toSdkSandboxUid(int uid) {
+ return uid + (FIRST_SDK_SANDBOX_UID - FIRST_APPLICATION_UID);
}
/**
- * Returns whether the current process is a supplemental process.
+ * Returns whether the current process is a sdk sandbox process.
*/
- public static final boolean isSupplemental() {
- return isSupplemental(myUid());
+ public static final boolean isSdkSandbox() {
+ return isSdkSandboxUid(myUid());
}
/**
diff --git a/core/java/android/os/vibrator/PrimitiveSegment.java b/core/java/android/os/vibrator/PrimitiveSegment.java
index 58ca978..2d287e9 100644
--- a/core/java/android/os/vibrator/PrimitiveSegment.java
+++ b/core/java/android/os/vibrator/PrimitiveSegment.java
@@ -108,7 +108,7 @@
Preconditions.checkArgumentInRange(mPrimitiveId, VibrationEffect.Composition.PRIMITIVE_NOOP,
VibrationEffect.Composition.PRIMITIVE_LOW_TICK, "primitiveId");
Preconditions.checkArgumentInRange(mScale, 0f, 1f, "scale");
- Preconditions.checkArgumentNonnegative(mDelay, "primitive delay should be >= 0");
+ VibrationEffectSegment.checkDurationArgument(mDelay, "delay");
}
@Override
diff --git a/core/java/android/os/vibrator/RampSegment.java b/core/java/android/os/vibrator/RampSegment.java
index 9e1f636..d7d8c49 100644
--- a/core/java/android/os/vibrator/RampSegment.java
+++ b/core/java/android/os/vibrator/RampSegment.java
@@ -108,14 +108,9 @@
/** @hide */
@Override
public void validate() {
- Preconditions.checkArgumentNonNegative(mStartFrequencyHz,
- "Frequencies must all be >= 0, got start frequency of " + mStartFrequencyHz);
- Preconditions.checkArgumentFinite(mStartFrequencyHz, "startFrequencyHz");
- Preconditions.checkArgumentNonNegative(mEndFrequencyHz,
- "Frequencies must all be >= 0, got end frequency of " + mEndFrequencyHz);
- Preconditions.checkArgumentFinite(mEndFrequencyHz, "endFrequencyHz");
- Preconditions.checkArgumentNonnegative(mDuration,
- "Durations must all be >= 0, got " + mDuration);
+ VibrationEffectSegment.checkFrequencyArgument(mStartFrequencyHz, "startFrequencyHz");
+ VibrationEffectSegment.checkFrequencyArgument(mEndFrequencyHz, "endFrequencyHz");
+ VibrationEffectSegment.checkDurationArgument(mDuration, "duration");
Preconditions.checkArgumentInRange(mStartAmplitude, 0f, 1f, "startAmplitude");
Preconditions.checkArgumentInRange(mEndAmplitude, 0f, 1f, "endAmplitude");
}
diff --git a/core/java/android/os/vibrator/StepSegment.java b/core/java/android/os/vibrator/StepSegment.java
index c679511..5a0bbf7 100644
--- a/core/java/android/os/vibrator/StepSegment.java
+++ b/core/java/android/os/vibrator/StepSegment.java
@@ -95,11 +95,8 @@
/** @hide */
@Override
public void validate() {
- Preconditions.checkArgumentNonNegative(mFrequencyHz,
- "Frequencies must all be >= 0, got " + mFrequencyHz);
- Preconditions.checkArgumentFinite(mFrequencyHz, "frequencyHz");
- Preconditions.checkArgumentNonnegative(mDuration,
- "Durations must all be >= 0, got " + mDuration);
+ VibrationEffectSegment.checkFrequencyArgument(mFrequencyHz, "frequencyHz");
+ VibrationEffectSegment.checkDurationArgument(mDuration, "duration");
if (Float.compare(mAmplitude, VibrationEffect.DEFAULT_AMPLITUDE) != 0) {
Preconditions.checkArgumentInRange(mAmplitude, 0f, 1f, "amplitude");
}
diff --git a/core/java/android/os/vibrator/VibrationEffectSegment.java b/core/java/android/os/vibrator/VibrationEffectSegment.java
index 979c447..be10553 100644
--- a/core/java/android/os/vibrator/VibrationEffectSegment.java
+++ b/core/java/android/os/vibrator/VibrationEffectSegment.java
@@ -112,6 +112,43 @@
@NonNull
public abstract <T extends VibrationEffectSegment> T applyEffectStrength(int effectStrength);
+ /**
+ * Checks the given frequency argument is valid to represent a vibration effect frequency in
+ * hertz, i.e. a finite non-negative value.
+ *
+ * @param value the frequency argument value to be checked
+ * @param name the argument name for the error message.
+ *
+ * @hide
+ */
+ public static void checkFrequencyArgument(float value, @NonNull String name) {
+ // Similar to combining Preconditions checkArgumentFinite + checkArgumentNonnegative,
+ // but this implementation doesn't create the error message unless a check fail.
+ if (Float.isNaN(value)) {
+ throw new IllegalArgumentException(name + " must not be NaN");
+ }
+ if (Float.isInfinite(value)) {
+ throw new IllegalArgumentException(name + " must not be infinite");
+ }
+ if (value < 0) {
+ throw new IllegalArgumentException(name + " must be >= 0, got " + value);
+ }
+ }
+
+ /**
+ * Checks the given duration argument is valid, i.e. a non-negative value.
+ *
+ * @param value the duration value to be checked
+ * @param name the argument name for the error message.
+ *
+ * @hide
+ */
+ public static void checkDurationArgument(long value, @NonNull String name) {
+ if (value < 0) {
+ throw new IllegalArgumentException(name + " must be >= 0, got " + value);
+ }
+ }
+
@NonNull
public static final Creator<VibrationEffectSegment> CREATOR =
new Creator<VibrationEffectSegment>() {
diff --git a/core/java/android/service/autofill/Dataset.java b/core/java/android/service/autofill/Dataset.java
index cfb6909..b701e07 100644
--- a/core/java/android/service/autofill/Dataset.java
+++ b/core/java/android/service/autofill/Dataset.java
@@ -905,7 +905,7 @@
if (field == null) {
setLifeTheUniverseAndEverything(id, null, null, null, null, null, null);
} else {
- final DatasetFieldFilter filter = field.getFilter();
+ final DatasetFieldFilter filter = field.getDatasetFieldFilter();
final Presentations presentations = field.getPresentations();
if (presentations == null) {
setLifeTheUniverseAndEverything(id, field.getValue(), null, null, null,
diff --git a/core/java/android/service/autofill/Field.java b/core/java/android/service/autofill/Field.java
index b7c0d82..8c905a6 100644
--- a/core/java/android/service/autofill/Field.java
+++ b/core/java/android/service/autofill/Field.java
@@ -18,7 +18,6 @@
import android.annotation.NonNull;
import android.annotation.Nullable;
-import android.annotation.SuppressLint;
import android.view.autofill.AutofillId;
import android.view.autofill.AutofillValue;
@@ -86,11 +85,21 @@
* @see Dataset.DatasetFieldFilter
* @hide
*/
- public @Nullable Dataset.DatasetFieldFilter getFilter() {
+ public @Nullable Dataset.DatasetFieldFilter getDatasetFieldFilter() {
return mFilter;
}
/**
+ * Regex used to determine if the dataset should be shown in the autofill UI;
+ * when {@code null}, it disables filtering on that dataset (this is the recommended
+ * approach when {@code value} is not {@code null} and field contains sensitive data
+ * such as passwords).
+ */
+ public @Nullable Pattern getFilter() {
+ return mFilter == null ? null : mFilter.pattern;
+ }
+
+ /**
* The presentations used to visualize this field in Autofill UI.
*/
public @Nullable Presentations getPresentations() {
@@ -127,7 +136,6 @@
* approach when {@code value} is not {@code null} and field contains sensitive data
* such as passwords).
*/
- @SuppressLint("MissingGetterMatchingBuilder")
public @NonNull Builder setFilter(@Nullable Pattern value) {
checkNotUsed();
mFilter = new Dataset.DatasetFieldFilter(value);
diff --git a/core/java/android/service/dreams/DreamService.java b/core/java/android/service/dreams/DreamService.java
index db622d3..8670759 100644
--- a/core/java/android/service/dreams/DreamService.java
+++ b/core/java/android/service/dreams/DreamService.java
@@ -231,7 +231,7 @@
* The default value for whether to show complications on the overlay.
* @hide
*/
- public static final boolean DEFAULT_SHOW_COMPLICATIONS = true;
+ public static final boolean DEFAULT_SHOW_COMPLICATIONS = false;
private final IDreamManager mDreamManager;
private final Handler mHandler = new Handler(Looper.getMainLooper());
diff --git a/core/java/android/view/IWindowManager.aidl b/core/java/android/view/IWindowManager.aidl
index 53b842a..f8a1b45 100644
--- a/core/java/android/view/IWindowManager.aidl
+++ b/core/java/android/view/IWindowManager.aidl
@@ -955,4 +955,10 @@
* @hide
*/
Bitmap snapshotTaskForRecents(int taskId);
+
+ /**
+ * Informs the system whether the recents app is currently behind the system bars. If so,
+ * means the recents app can control the SystemUI flags, and vice-versa.
+ */
+ void setRecentsAppBehindSystemBars(boolean behindSystemBars);
}
diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java
index 8bb7e67..a9a2689 100644
--- a/core/java/android/view/ViewRootImpl.java
+++ b/core/java/android/view/ViewRootImpl.java
@@ -76,6 +76,7 @@
import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_FIT_INSETS_CONTROLLED;
import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_DECOR_VIEW_VISIBILITY;
import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_INSET_PARENT_FRAME_BY_IME;
+import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_LAYOUT_SIZE_EXTENDED_BY_CUTOUT;
import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
import static android.view.WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST;
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
@@ -2462,8 +2463,9 @@
if (DEBUG_DIALOG) Log.v(mTag, "Window " + mView + ": baseSize=" + baseSize
+ ", desiredWindowWidth=" + desiredWindowWidth);
if (baseSize != 0 && desiredWindowWidth > baseSize) {
- childWidthMeasureSpec = getRootMeasureSpec(baseSize, lp.width);
- childHeightMeasureSpec = getRootMeasureSpec(desiredWindowHeight, lp.height);
+ childWidthMeasureSpec = getRootMeasureSpec(baseSize, lp.width, lp.privateFlags);
+ childHeightMeasureSpec = getRootMeasureSpec(desiredWindowHeight, lp.height,
+ lp.privateFlags);
performMeasure(childWidthMeasureSpec, childHeightMeasureSpec);
if (DEBUG_DIALOG) Log.v(mTag, "Window " + mView + ": measured ("
+ host.getMeasuredWidth() + "," + host.getMeasuredHeight()
@@ -2476,7 +2478,7 @@
baseSize = (baseSize+desiredWindowWidth)/2;
if (DEBUG_DIALOG) Log.v(mTag, "Window " + mView + ": next baseSize="
+ baseSize);
- childWidthMeasureSpec = getRootMeasureSpec(baseSize, lp.width);
+ childWidthMeasureSpec = getRootMeasureSpec(baseSize, lp.width, lp.privateFlags);
performMeasure(childWidthMeasureSpec, childHeightMeasureSpec);
if (DEBUG_DIALOG) Log.v(mTag, "Window " + mView + ": measured ("
+ host.getMeasuredWidth() + "," + host.getMeasuredHeight() + ")");
@@ -2489,8 +2491,10 @@
}
if (!goodMeasure) {
- childWidthMeasureSpec = getRootMeasureSpec(desiredWindowWidth, lp.width);
- childHeightMeasureSpec = getRootMeasureSpec(desiredWindowHeight, lp.height);
+ childWidthMeasureSpec = getRootMeasureSpec(desiredWindowWidth, lp.width,
+ lp.privateFlags);
+ childHeightMeasureSpec = getRootMeasureSpec(desiredWindowHeight, lp.height,
+ lp.privateFlags);
performMeasure(childWidthMeasureSpec, childHeightMeasureSpec);
if (mWidth != host.getMeasuredWidth() || mHeight != host.getMeasuredHeight()) {
windowSizeMayChange = true;
@@ -3150,8 +3154,10 @@
if (focusChangedDueToTouchMode || mWidth != host.getMeasuredWidth()
|| mHeight != host.getMeasuredHeight() || dispatchApplyInsets ||
updatedConfiguration) {
- int childWidthMeasureSpec = getRootMeasureSpec(mWidth, lp.width);
- int childHeightMeasureSpec = getRootMeasureSpec(mHeight, lp.height);
+ int childWidthMeasureSpec = getRootMeasureSpec(mWidth, lp.width,
+ lp.privateFlags);
+ int childHeightMeasureSpec = getRootMeasureSpec(mHeight, lp.height,
+ lp.privateFlags);
if (DEBUG_LAYOUT) Log.v(mTag, "Ooops, something changed! mWidth="
+ mWidth + " measuredWidth=" + host.getMeasuredWidth()
@@ -3951,31 +3957,28 @@
* Figures out the measure spec for the root view in a window based on it's
* layout params.
*
- * @param windowSize
- * The available width or height of the window
- *
- * @param rootDimension
- * The layout params for one dimension (width or height) of the
- * window.
- *
+ * @param windowSize The available width or height of the window.
+ * @param measurement The layout width or height requested in the layout params.
+ * @param privateFlags The private flags in the layout params of the window.
* @return The measure spec to use to measure the root view.
*/
- private static int getRootMeasureSpec(int windowSize, int rootDimension) {
+ private static int getRootMeasureSpec(int windowSize, int measurement, int privateFlags) {
int measureSpec;
+ final int rootDimension = (privateFlags & PRIVATE_FLAG_LAYOUT_SIZE_EXTENDED_BY_CUTOUT) != 0
+ ? MATCH_PARENT : measurement;
switch (rootDimension) {
-
- case ViewGroup.LayoutParams.MATCH_PARENT:
- // Window can't resize. Force root view to be windowSize.
- measureSpec = MeasureSpec.makeMeasureSpec(windowSize, MeasureSpec.EXACTLY);
- break;
- case ViewGroup.LayoutParams.WRAP_CONTENT:
- // Window can resize. Set max size for root view.
- measureSpec = MeasureSpec.makeMeasureSpec(windowSize, MeasureSpec.AT_MOST);
- break;
- default:
- // Window wants to be an exact size. Force root view to be that size.
- measureSpec = MeasureSpec.makeMeasureSpec(rootDimension, MeasureSpec.EXACTLY);
- break;
+ case ViewGroup.LayoutParams.MATCH_PARENT:
+ // Window can't resize. Force root view to be windowSize.
+ measureSpec = MeasureSpec.makeMeasureSpec(windowSize, MeasureSpec.EXACTLY);
+ break;
+ case ViewGroup.LayoutParams.WRAP_CONTENT:
+ // Window can resize. Set max size for root view.
+ measureSpec = MeasureSpec.makeMeasureSpec(windowSize, MeasureSpec.AT_MOST);
+ break;
+ default:
+ // Window wants to be an exact size. Force root view to be that size.
+ measureSpec = MeasureSpec.makeMeasureSpec(rootDimension, MeasureSpec.EXACTLY);
+ break;
}
return measureSpec;
}
diff --git a/core/java/android/view/WindowLayout.java b/core/java/android/view/WindowLayout.java
index 27f89ec..ad9f21b 100644
--- a/core/java/android/view/WindowLayout.java
+++ b/core/java/android/view/WindowLayout.java
@@ -16,6 +16,8 @@
package android.view;
+import static android.view.Gravity.DISPLAY_CLIP_HORIZONTAL;
+import static android.view.Gravity.DISPLAY_CLIP_VERTICAL;
import static android.view.InsetsState.ITYPE_IME;
import static android.view.InsetsState.ITYPE_NAVIGATION_BAR;
import static android.view.InsetsState.ITYPE_STATUS_BAR;
@@ -29,6 +31,7 @@
import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_INSET_PARENT_FRAME_BY_IME;
import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME;
+import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_LAYOUT_SIZE_EXTENDED_BY_CUTOUT;
import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
@@ -250,11 +253,39 @@
Gravity.apply(attrs.gravity, w, h, outParentFrame,
(int) (x + attrs.horizontalMargin * pw),
(int) (y + attrs.verticalMargin * ph), outFrame);
+
// Now make sure the window fits in the overall display frame.
if (fitToDisplay) {
Gravity.applyDisplay(attrs.gravity, outDisplayFrame, outFrame);
}
+ if ((attrs.privateFlags & PRIVATE_FLAG_LAYOUT_SIZE_EXTENDED_BY_CUTOUT) != 0
+ && !cutout.isEmpty()) {
+ // If the actual frame covering a display cutout, and the window is requesting to extend
+ // it's requested frame, re-do the frame calculation after getting the new requested
+ // size.
+ mTempRect.set(outFrame);
+ // Do nothing if the display cutout and window don't overlap entirely. This may happen
+ // when the cutout is not on the same side with the window.
+ boolean shouldExpand = false;
+ final Rect [] cutoutBounds = cutout.getBoundingRectsAll();
+ for (Rect cutoutBound : cutoutBounds) {
+ if (cutoutBound.isEmpty()) continue;
+ if (mTempRect.contains(cutoutBound) || cutoutBound.contains(mTempRect)) {
+ shouldExpand = true;
+ break;
+ }
+ }
+ if (shouldExpand) {
+ // Try to fit move the bar to avoid the display cutout first. Make sure the clip
+ // flags are not set to make the window move.
+ final int clipFlags = DISPLAY_CLIP_VERTICAL | DISPLAY_CLIP_HORIZONTAL;
+ Gravity.applyDisplay(attrs.gravity & ~clipFlags, displayCutoutSafe,
+ mTempRect);
+ outFrame.union(mTempRect);
+ }
+ }
+
if (DEBUG) Log.d(TAG, "computeWindowFrames " + attrs.getTitle()
+ " outFrame=" + outFrame.toShortString()
+ " outParentFrame=" + outParentFrame.toShortString()
diff --git a/core/java/android/view/WindowManager.java b/core/java/android/view/WindowManager.java
index 8ee3e43..dbfae46 100644
--- a/core/java/android/view/WindowManager.java
+++ b/core/java/android/view/WindowManager.java
@@ -2385,6 +2385,16 @@
public static final int PRIVATE_FLAG_FORCE_SHOW_STATUS_BAR = 0x00001000;
/**
+ * Flag to indicate that the window frame should be the requested frame adding the display
+ * cutout frame. This will only be applied if a specific size smaller than the parent frame
+ * is given, and the window is covering the display cutout. The extended frame will not be
+ * larger than the parent frame.
+ *
+ * {@hide}
+ */
+ public static final int PRIVATE_FLAG_LAYOUT_SIZE_EXTENDED_BY_CUTOUT = 0x00002000;
+
+ /**
* Flag that will make window ignore app visibility and instead depend purely on the decor
* view visibility for determining window visibility. This is used by recents to keep
* drawing after it launches an app.
diff --git a/core/java/android/view/WindowManagerGlobal.java b/core/java/android/view/WindowManagerGlobal.java
index 93cb0dd7..2dc5fbd 100644
--- a/core/java/android/view/WindowManagerGlobal.java
+++ b/core/java/android/view/WindowManagerGlobal.java
@@ -752,6 +752,14 @@
public void removeWindowlessRoot(ViewRootImpl impl) {
synchronized (mLock) {
mWindowlessRoots.remove(impl);
+ }
+ }
+
+ public void setRecentsAppBehindSystemBars(boolean behindSystemBars) {
+ try {
+ getWindowManagerService().setRecentsAppBehindSystemBars(behindSystemBars);
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
}
}
}
diff --git a/core/java/android/window/WindowContainerTransaction.java b/core/java/android/window/WindowContainerTransaction.java
index 346aa33..35c9594 100644
--- a/core/java/android/window/WindowContainerTransaction.java
+++ b/core/java/android/window/WindowContainerTransaction.java
@@ -31,6 +31,7 @@
import android.os.Parcel;
import android.os.Parcelable;
import android.util.ArrayMap;
+import android.view.InsetsState;
import android.view.SurfaceControl;
import java.util.ArrayList;
@@ -589,6 +590,56 @@
}
/**
+ * Adds a given {@code Rect} as a rect insets provider on the {@code receiverWindowContainer}.
+ * This will trigger a change of insets for all the children in the subtree of
+ * {@code receiverWindowContainer}.
+ *
+ * @param receiverWindowContainer the window container which the insets provider need to be
+ * added to
+ * @param insetsProviderFrame the frame that will be added as Insets provider
+ * @param insetsTypes types of insets the rect provides
+ * @hide
+ */
+ @NonNull
+ public WindowContainerTransaction addRectInsetsProvider(
+ @NonNull WindowContainerToken receiverWindowContainer,
+ @NonNull Rect insetsProviderFrame,
+ @InsetsState.InternalInsetsType int[] insetsTypes) {
+ final HierarchyOp hierarchyOp =
+ new HierarchyOp.Builder(
+ HierarchyOp.HIERARCHY_OP_TYPE_ADD_RECT_INSETS_PROVIDER)
+ .setContainer(receiverWindowContainer.asBinder())
+ .setInsetsProviderFrame(insetsProviderFrame)
+ .setInsetsTypes(insetsTypes)
+ .build();
+ mHierarchyOps.add(hierarchyOp);
+ return this;
+ }
+
+ /**
+ * Removes the insets provider for the given types from the
+ * {@code receiverWindowContainer}. This will trigger a change of insets for all the children
+ * in the subtree of {@code receiverWindowContainer}.
+ *
+ * @param receiverWindowContainer the window container which the insets-override-provider has
+ * to be removed from
+ * @param insetsTypes types of insets that have to be removed
+ * @hide
+ */
+ @NonNull
+ public WindowContainerTransaction removeInsetsProvider(
+ @NonNull WindowContainerToken receiverWindowContainer,
+ @InsetsState.InternalInsetsType int[] insetsTypes) {
+ final HierarchyOp hierarchyOp =
+ new HierarchyOp.Builder(HierarchyOp.HIERARCHY_OP_TYPE_REMOVE_INSETS_PROVIDER)
+ .setContainer(receiverWindowContainer.asBinder())
+ .setInsetsTypes(insetsTypes)
+ .build();
+ mHierarchyOps.add(hierarchyOp);
+ return this;
+ }
+
+ /**
* When this {@link WindowContainerTransaction} failed to finish on the server side, it will
* trigger callback with this {@param errorCallbackToken}.
* @param errorCallbackToken client provided token that will be passed back as parameter in
@@ -993,6 +1044,8 @@
public static final int HIERARCHY_OP_TYPE_SET_ADJACENT_TASK_FRAGMENTS = 13;
public static final int HIERARCHY_OP_TYPE_START_SHORTCUT = 14;
public static final int HIERARCHY_OP_TYPE_RESTORE_TRANSIENT_ORDER = 15;
+ public static final int HIERARCHY_OP_TYPE_ADD_RECT_INSETS_PROVIDER = 16;
+ public static final int HIERARCHY_OP_TYPE_REMOVE_INSETS_PROVIDER = 17;
// The following key(s) are for use with mLaunchOptions:
// When launching a task (eg. from recents), this is the taskId to be launched.
@@ -1012,6 +1065,10 @@
@Nullable
private IBinder mReparent;
+ private @InsetsState.InternalInsetsType int[] mInsetsTypes;
+
+ private Rect mInsetsProviderFrame;
+
// Moves/reparents to top of parent when {@code true}, otherwise moves/reparents to bottom.
private boolean mToTop;
@@ -1130,6 +1187,8 @@
mType = copy.mType;
mContainer = copy.mContainer;
mReparent = copy.mReparent;
+ mInsetsTypes = copy.mInsetsTypes;
+ mInsetsProviderFrame = copy.mInsetsProviderFrame;
mToTop = copy.mToTop;
mReparentTopOnly = copy.mReparentTopOnly;
mMoveAdjacentTogether = copy.mMoveAdjacentTogether;
@@ -1146,6 +1205,12 @@
mType = in.readInt();
mContainer = in.readStrongBinder();
mReparent = in.readStrongBinder();
+ mInsetsTypes = in.createIntArray();
+ if (in.readInt() != 0) {
+ mInsetsProviderFrame = Rect.CREATOR.createFromParcel(in);
+ } else {
+ mInsetsProviderFrame = null;
+ }
mToTop = in.readBoolean();
mReparentTopOnly = in.readBoolean();
mMoveAdjacentTogether = in.readBoolean();
@@ -1171,6 +1236,15 @@
return mReparent;
}
+ @Nullable
+ public @InsetsState.InternalInsetsType int[] getInsetsTypes() {
+ return mInsetsTypes;
+ }
+
+ public Rect getInsetsProviderFrame() {
+ return mInsetsProviderFrame;
+ }
+
@NonNull
public IBinder getContainer() {
return mContainer;
@@ -1276,6 +1350,13 @@
case HIERARCHY_OP_TYPE_START_SHORTCUT:
return "{StartShortcut: options=" + mLaunchOptions + " info=" + mShortcutInfo
+ "}";
+ case HIERARCHY_OP_TYPE_ADD_RECT_INSETS_PROVIDER:
+ return "{addRectInsetsProvider: container=" + mContainer
+ + " insetsProvidingFrame=" + mInsetsProviderFrame
+ + " insetsType=" + Arrays.toString(mInsetsTypes) + "}";
+ case HIERARCHY_OP_TYPE_REMOVE_INSETS_PROVIDER:
+ return "{removeLocalInsetsProvider: container=" + mContainer
+ + " insetsType=" + Arrays.toString(mInsetsTypes) + "}";
default:
return "{mType=" + mType + " container=" + mContainer + " reparent=" + mReparent
+ " mToTop=" + mToTop
@@ -1289,6 +1370,13 @@
dest.writeInt(mType);
dest.writeStrongBinder(mContainer);
dest.writeStrongBinder(mReparent);
+ dest.writeIntArray(mInsetsTypes);
+ if (mInsetsProviderFrame != null) {
+ dest.writeInt(1);
+ mInsetsProviderFrame.writeToParcel(dest, 0);
+ } else {
+ dest.writeInt(0);
+ }
dest.writeBoolean(mToTop);
dest.writeBoolean(mReparentTopOnly);
dest.writeBoolean(mMoveAdjacentTogether);
@@ -1328,6 +1416,10 @@
@Nullable
private IBinder mReparent;
+ private int[] mInsetsTypes;
+
+ private Rect mInsetsProviderFrame;
+
private boolean mToTop;
private boolean mReparentTopOnly;
@@ -1369,6 +1461,16 @@
return this;
}
+ Builder setInsetsTypes(int[] insetsTypes) {
+ mInsetsTypes = insetsTypes;
+ return this;
+ }
+
+ Builder setInsetsProviderFrame(Rect insetsProviderFrame) {
+ mInsetsProviderFrame = insetsProviderFrame;
+ return this;
+ }
+
Builder setToTop(boolean toTop) {
mToTop = toTop;
return this;
@@ -1430,6 +1532,8 @@
hierarchyOp.mActivityTypes = mActivityTypes != null
? Arrays.copyOf(mActivityTypes, mActivityTypes.length)
: null;
+ hierarchyOp.mInsetsTypes = mInsetsTypes;
+ hierarchyOp.mInsetsProviderFrame = mInsetsProviderFrame;
hierarchyOp.mToTop = mToTop;
hierarchyOp.mReparentTopOnly = mReparentTopOnly;
hierarchyOp.mMoveAdjacentTogether = mMoveAdjacentTogether;
diff --git a/core/java/com/android/server/SystemConfig.java b/core/java/com/android/server/SystemConfig.java
index 93864fa..b1846d2 100644
--- a/core/java/com/android/server/SystemConfig.java
+++ b/core/java/com/android/server/SystemConfig.java
@@ -671,6 +671,7 @@
readPermissions(parser, Environment.buildPath(f, "etc", "permissions"),
apexPermissionFlag);
}
+ pruneVendorApexPrivappAllowlists();
}
@VisibleForTesting
@@ -1197,7 +1198,8 @@
readPrivAppPermissions(parser, mSystemExtPrivAppPermissions,
mSystemExtPrivAppDenyPermissions);
} else if (apex) {
- readApexPrivAppPermissions(parser, permFile);
+ readApexPrivAppPermissions(parser, permFile,
+ Environment.getApexDirectory().toPath());
} else {
readPrivAppPermissions(parser, mPrivAppPermissions,
mPrivAppDenyPermissions);
@@ -1547,6 +1549,21 @@
}
}
+ /**
+ * Prunes out any privileged permission allowlists bundled in vendor apexes.
+ */
+ @VisibleForTesting
+ public void pruneVendorApexPrivappAllowlists() {
+ for (String moduleName: mAllowedVendorApexes.keySet()) {
+ if (mApexPrivAppPermissions.containsKey(moduleName)
+ || mApexPrivAppDenyPermissions.containsKey(moduleName)) {
+ Slog.w(TAG, moduleName + " is a vendor apex, ignore its priv-app allowlist");
+ mApexPrivAppPermissions.remove(moduleName);
+ mApexPrivAppDenyPermissions.remove(moduleName);
+ }
+ }
+ }
+
private void readInstallInUserType(XmlPullParser parser,
Map<String, Set<String>> doInstallMap,
Map<String, Set<String>> nonInstallMap)
@@ -1757,8 +1774,7 @@
/**
* Returns the module name for a file in the apex module's partition.
*/
- private String getApexModuleNameFromFilePath(Path path) {
- final Path apexDirectoryPath = Environment.getApexDirectory().toPath();
+ private String getApexModuleNameFromFilePath(Path path, Path apexDirectoryPath) {
if (!path.startsWith(apexDirectoryPath)) {
throw new IllegalArgumentException("File " + path + " is not part of an APEX.");
}
@@ -1770,9 +1786,14 @@
return path.getName(apexDirectoryPath.getNameCount()).toString();
}
- private void readApexPrivAppPermissions(XmlPullParser parser, File permFile)
- throws IOException, XmlPullParserException {
- final String moduleName = getApexModuleNameFromFilePath(permFile.toPath());
+ /**
+ * Reads the contents of the privileged permission allowlist stored inside an APEX.
+ */
+ @VisibleForTesting
+ public void readApexPrivAppPermissions(XmlPullParser parser, File permFile,
+ Path apexDirectoryPath) throws IOException, XmlPullParserException {
+ final String moduleName =
+ getApexModuleNameFromFilePath(permFile.toPath(), apexDirectoryPath);
final ArrayMap<String, ArraySet<String>> privAppPermissions;
if (mApexPrivAppPermissions.containsKey(moduleName)) {
privAppPermissions = mApexPrivAppPermissions.get(moduleName);
diff --git a/core/jni/android_media_AudioSystem.cpp b/core/jni/android_media_AudioSystem.cpp
index 90b272c..e781760 100644
--- a/core/jni/android_media_AudioSystem.cpp
+++ b/core/jni/android_media_AudioSystem.cpp
@@ -829,13 +829,6 @@
}
static jint
-android_media_AudioSystem_getDevicesForStream(JNIEnv *env, jobject thiz, jint stream)
-{
- return (jint)deviceTypesToBitMask(
- AudioSystem::getDevicesForStream(static_cast<audio_stream_type_t>(stream)));
-}
-
-static jint
android_media_AudioSystem_getPrimaryOutputSamplingRate(JNIEnv *env, jobject clazz)
{
return (jint) AudioSystem::getPrimaryOutputSamplingRate();
@@ -2959,7 +2952,6 @@
{"getMasterMono", "()Z", (void *)android_media_AudioSystem_getMasterMono},
{"setMasterBalance", "(F)I", (void *)android_media_AudioSystem_setMasterBalance},
{"getMasterBalance", "()F", (void *)android_media_AudioSystem_getMasterBalance},
- {"getDevicesForStream", "(I)I", (void *)android_media_AudioSystem_getDevicesForStream},
{"getPrimaryOutputSamplingRate", "()I",
(void *)android_media_AudioSystem_getPrimaryOutputSamplingRate},
{"getPrimaryOutputFrameCount", "()I",
diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml
index 58a3bb4..73cdaba 100644
--- a/core/res/AndroidManifest.xml
+++ b/core/res/AndroidManifest.xml
@@ -1903,14 +1903,16 @@
to improve wifi performance.
<p>Not for use by third-party applications. -->
<permission android:name="android.permission.MANAGE_WIFI_AUTO_JOIN"
- android:protectionLevel="signature|privileged" />
+ android:protectionLevel="signature|privileged|knownSigner"
+ android:knownCerts="@array/wifi_known_signers" />
<!-- Allows applications to get notified when a Wi-Fi interface request cannot
be satisfied without tearing down one or more other interfaces, and provide a decision
whether to approve the request or reject it.
<p>Not for use by third-party applications. -->
<permission android:name="android.permission.MANAGE_WIFI_INTERFACES"
- android:protectionLevel="signature|privileged" />
+ android:protectionLevel="signature|privileged|knownSigner"
+ android:knownCerts="@array/wifi_known_signers" />
<!-- @SystemApi @hide Allows apps to create and manage IPsec tunnels.
<p>Only granted to applications that are currently bound by the
@@ -1948,7 +1950,8 @@
modifications.
<p>Not for use by third-party applications. -->
<permission android:name="android.permission.OVERRIDE_WIFI_CONFIG"
- android:protectionLevel="signature|privileged" />
+ android:protectionLevel="signature|privileged|knownSigner"
+ android:knownCerts="@array/wifi_known_signers" />
<!-- @deprecated Allows applications to act as network scorers. @hide @SystemApi-->
<permission android:name="android.permission.SCORE_NETWORKS"
diff --git a/core/res/res/values/arrays.xml b/core/res/res/values/arrays.xml
index 8f2d6c3..dff7751 100644
--- a/core/res/res/values/arrays.xml
+++ b/core/res/res/values/arrays.xml
@@ -185,6 +185,12 @@
<item>@string/app_info</item>
</string-array>
+ <!-- Certificate digests for trusted apps that will be allowed to obtain the knownSigner Wi-Fi
+ permissions. The digest should be computed over the DER encoding of the trusted certificate
+ using the SHA-256 digest algorithm. -->
+ <string-array name="wifi_known_signers">
+ </string-array>
+
<!-- Device-specific array of SIM slot indexes which are are embedded eUICCs.
e.g. If a device has two physical slots with indexes 0, 1, and slot 1 is an
eUICC, then the value of this array should be:
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml
index 5ac30de..0763ddb 100644
--- a/core/res/res/values/config.xml
+++ b/core/res/res/values/config.xml
@@ -1207,13 +1207,13 @@
<!-- Display low battery warning when battery level dips to this value.
Also, the battery stats are flushed to disk when we hit this level. -->
- <integer name="config_criticalBatteryWarningLevel">5</integer>
+ <integer name="config_criticalBatteryWarningLevel">10</integer>
<!-- Shutdown if the battery temperature exceeds (this value * 0.1) Celsius. -->
<integer name="config_shutdownBatteryTemperature">680</integer>
<!-- Display low battery warning when battery level dips to this value -->
- <integer name="config_lowBatteryWarningLevel">15</integer>
+ <integer name="config_lowBatteryWarningLevel">20</integer>
<!-- The default suggested battery % at which we enable battery saver automatically. -->
<integer name="config_lowBatteryAutoTriggerDefaultLevel">15</integer>
@@ -2113,7 +2113,7 @@
TODO(b/189347385) make this a @SystemAPI -->
<string name="config_systemTelevisionRemoteService" translatable="false">@string/config_tvRemoteServicePackage</string>
<!-- The name of the package that will hold the device management role -->
- <string name="config_deviceManager" translatable="false"></string>
+ <string name="config_devicePolicyManagement" translatable="false"></string>
<!-- The name of the package that will hold the app protection service role. -->
<string name="config_systemAppProtectionService" translatable="false"></string>
<!-- The name of the package that will hold the system calendar sync manager role. -->
@@ -2122,7 +2122,7 @@
<string name="config_defaultAutomotiveNavigation" translatable="false"></string>
<!-- The name of the package that will handle updating the device management role. -->
- <string name="config_deviceManagerUpdater" translatable="false"></string>
+ <string name="config_devicePolicyManagementUpdater" translatable="false"></string>
<!-- The name of the package that will be allowed to change its components' label/icon. -->
<string name="config_overrideComponentUiPackage" translatable="false">com.android.stk</string>
@@ -4130,9 +4130,9 @@
This service must be trusted, as it can be activated without explicit consent of the user.
If no service with the specified name exists on the device, cloudsearch will be disabled.
Example: "com.android.intelligence/.CloudSearchService"
- config_defaultCloudSearchService is for the single provider case.
+ config_defaultCloudSearchServices is for the multiple provider case.
-->
- <string name="config_defaultCloudSearchService" translatable="false"></string>
+ <string-array name="config_defaultCloudSearchServices"></string-array>
<!-- The package name for the system's translation service.
This service must be trusted, as it can be activated without explicit consent of the user.
diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml
index 3beb4b2..3467e1b 100644
--- a/core/res/res/values/public.xml
+++ b/core/res/res/values/public.xml
@@ -3301,7 +3301,7 @@
<!-- @hide @SystemApi -->
<public name="config_systemSupervision" />
<!-- @hide @SystemApi -->
- <public name="config_deviceManager" />
+ <public name="config_devicePolicyManagement" />
<!-- @hide @SystemApi -->
<public name="config_systemAppProtectionService" />
<!-- @hide @SystemApi @TestApi -->
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index e543034..dae746b 100644
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -3675,7 +3675,7 @@
<java-symbol type="string" name="notification_channel_network_status" />
<java-symbol type="string" name="notification_channel_network_alerts" />
<java-symbol type="string" name="notification_channel_network_available" />
- <java-symbol type="string" name="config_defaultCloudSearchService" />
+ <java-symbol type="array" name="config_defaultCloudSearchServices" />
<java-symbol type="string" name="notification_channel_vpn" />
<java-symbol type="string" name="notification_channel_device_admin" />
<java-symbol type="string" name="notification_channel_alerts" />
@@ -4726,7 +4726,7 @@
<java-symbol type="bool" name="config_enableSafetyCenter" />
- <java-symbol type="string" name="config_deviceManagerUpdater" />
+ <java-symbol type="string" name="config_devicePolicyManagementUpdater" />
<java-symbol type="string" name="config_deviceSpecificDeviceStatePolicyProvider" />
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTransition.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTransition.java
index 91615fe..f01457b 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTransition.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTransition.java
@@ -84,6 +84,7 @@
private final Optional<SplitScreenController> mSplitScreenOptional;
private @PipAnimationController.AnimationType int mOneShotAnimationType = ANIM_TYPE_BOUNDS;
private Transitions.TransitionFinishCallback mFinishCallback;
+ private SurfaceControl.Transaction mFinishTransaction;
private final Rect mExitDestinationBounds = new Rect();
@Nullable
private IBinder mExitTransition;
@@ -166,6 +167,7 @@
if (mFinishCallback != null) {
mFinishCallback.onTransitionFinished(null, null);
mFinishCallback = null;
+ mFinishTransaction = null;
throw new RuntimeException("Previous callback not called, aborting exit PIP.");
}
@@ -267,7 +269,8 @@
public void onFinishResize(TaskInfo taskInfo, Rect destinationBounds,
@PipAnimationController.TransitionDirection int direction,
@Nullable SurfaceControl.Transaction tx) {
- if (isInPipDirection(direction)) {
+ final boolean enteringPip = isInPipDirection(direction);
+ if (enteringPip) {
mPipTransitionState.setTransitionState(ENTERED_PIP);
}
// If there is an expected exit transition, then the exit will be "merged" into this
@@ -279,6 +282,20 @@
if (tx != null) {
wct.setBoundsChangeTransaction(taskInfo.token, tx);
}
+ final SurfaceControl leash = mPipOrganizer.getSurfaceControl();
+ final int displayRotation = taskInfo.getConfiguration().windowConfiguration
+ .getDisplayRotation();
+ if (enteringPip && mInFixedRotation && mEndFixedRotation != displayRotation
+ && leash != null && leash.isValid()) {
+ // Launcher may update the Shelf height during the animation, which will update the
+ // destination bounds. Because this is in fixed rotation, We need to make sure the
+ // finishTransaction is using the updated bounds in the display rotation.
+ final Rect displayBounds = mPipBoundsState.getDisplayBounds();
+ final Rect finishBounds = new Rect(destinationBounds);
+ rotateBounds(finishBounds, displayBounds, mEndFixedRotation, displayRotation);
+ mSurfaceTransactionHelper.crop(mFinishTransaction, leash, finishBounds);
+ }
+ mFinishTransaction = null;
mFinishCallback.onTransitionFinished(wct, null /* callback */);
mFinishCallback = null;
}
@@ -290,6 +307,7 @@
if (mFinishCallback == null) return;
mFinishCallback.onTransitionFinished(null /* wct */, null /* callback */);
mFinishCallback = null;
+ mFinishTransaction = null;
}
@Override
@@ -336,6 +354,7 @@
mPipOrganizer.onExitPipFinished(pipChange.getTaskInfo());
finishCallback.onTransitionFinished(wct, wctCB);
};
+ mFinishTransaction = finishTransaction;
// Check if it is Shell rotation.
if (Transitions.SHELL_TRANSITIONS_ROTATION) {
@@ -526,6 +545,7 @@
if (mFinishCallback != null) {
mFinishCallback.onTransitionFinished(null /* wct */, null /* callback */);
mFinishCallback = null;
+ mFinishTransaction = null;
throw new RuntimeException("Previous callback not called, aborting entering PIP.");
}
@@ -549,6 +569,7 @@
mPipTransitionState.setTransitionState(PipTransitionState.ENTERING_PIP);
mFinishCallback = finishCallback;
+ mFinishTransaction = finishTransaction;
final int endRotation = mInFixedRotation ? mEndFixedRotation : enterPip.getEndRotation();
return startEnterAnimation(enterPip.getTaskInfo(), enterPip.getLeash(),
startTransaction, finishTransaction, enterPip.getStartRotation(),
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/startingsurface/StartingSurfaceDrawer.java b/libs/WindowManager/Shell/src/com/android/wm/shell/startingsurface/StartingSurfaceDrawer.java
index 3442699..61cbf6e 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/startingsurface/StartingSurfaceDrawer.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/startingsurface/StartingSurfaceDrawer.java
@@ -364,6 +364,12 @@
final StartingWindowRecord record = mStartingWindowRecords.get(taskId);
final SplashScreenView contentView = viewSupplier.get();
record.mBGColor = contentView.getInitBackgroundColor();
+ } else {
+ // release the icon view host
+ final SplashScreenView contentView = viewSupplier.get();
+ if (contentView.getSurfaceHost() != null) {
+ SplashScreenView.releaseIconHost(contentView.getSurfaceHost());
+ }
}
} catch (RuntimeException e) {
// don't crash if something else bad happens, for example a
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/transition/DefaultTransitionHandler.java b/libs/WindowManager/Shell/src/com/android/wm/shell/transition/DefaultTransitionHandler.java
index 4bc5850..56d5168 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/transition/DefaultTransitionHandler.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/transition/DefaultTransitionHandler.java
@@ -348,12 +348,13 @@
for (int i = info.getChanges().size() - 1; i >= 0; --i) {
final TransitionInfo.Change change = info.getChanges().get(i);
final boolean isTask = change.getTaskInfo() != null;
+ boolean isSeamlessDisplayChange = false;
if (change.getMode() == TRANSIT_CHANGE && (change.getFlags() & FLAG_IS_DISPLAY) != 0) {
if (info.getType() == TRANSIT_CHANGE) {
- boolean isSeamless = isRotationSeamless(info, mDisplayController);
+ isSeamlessDisplayChange = isRotationSeamless(info, mDisplayController);
final int anim = getRotationAnimation(info);
- if (!(isSeamless || anim == ROTATION_ANIMATION_JUMPCUT)) {
+ if (!(isSeamlessDisplayChange || anim == ROTATION_ANIMATION_JUMPCUT)) {
mRotationAnimation = new ScreenRotationAnimation(mContext, mSurfaceSession,
mTransactionPool, startTransaction, change, info.getRootLeash(),
anim);
@@ -387,6 +388,8 @@
startTransaction.setPosition(change.getLeash(),
change.getEndAbsBounds().left - info.getRootOffset().x,
change.getEndAbsBounds().top - info.getRootOffset().y);
+ // Seamless display transition doesn't need to animate.
+ if (isSeamlessDisplayChange) continue;
if (isTask) {
// Skip non-tasks since those usually have null bounds.
startTransaction.setWindowCrop(change.getLeash(),
diff --git a/media/java/android/media/AudioManager.java b/media/java/android/media/AudioManager.java
index 6c99a07..3a2f0d9 100644
--- a/media/java/android/media/AudioManager.java
+++ b/media/java/android/media/AudioManager.java
@@ -5624,27 +5624,33 @@
* Note that the information may be imprecise when the implementation
* cannot distinguish whether a particular device is enabled.
*
- * {@hide}
+ * @deprecated on {@link android.os.Build.VERSION_CODES#T} as new devices
+ * will have multi-bit device types.
+ * Prefer to use {@link #getDevicesForAttributes()} instead,
+ * noting that getDevicesForStream() has a few small discrepancies
+ * for better volume handling.
+ * @hide
*/
@UnsupportedAppUsage
+ @Deprecated
public int getDevicesForStream(int streamType) {
switch (streamType) {
- case STREAM_VOICE_CALL:
- case STREAM_SYSTEM:
- case STREAM_RING:
- case STREAM_MUSIC:
- case STREAM_ALARM:
- case STREAM_NOTIFICATION:
- case STREAM_DTMF:
- case STREAM_ACCESSIBILITY:
- final IAudioService service = getService();
- try {
- return service.getDevicesForStream(streamType);
- } catch (RemoteException e) {
- throw e.rethrowFromSystemServer();
- }
- default:
- return 0;
+ case STREAM_VOICE_CALL:
+ case STREAM_SYSTEM:
+ case STREAM_RING:
+ case STREAM_MUSIC:
+ case STREAM_ALARM:
+ case STREAM_NOTIFICATION:
+ case STREAM_DTMF:
+ case STREAM_ACCESSIBILITY:
+ final IAudioService service = getService();
+ try {
+ return service.getDeviceMaskForStream(streamType);
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
+ default:
+ return 0;
}
}
diff --git a/media/java/android/media/AudioSystem.java b/media/java/android/media/AudioSystem.java
index 210f3e5..acb34b5 100644
--- a/media/java/android/media/AudioSystem.java
+++ b/media/java/android/media/AudioSystem.java
@@ -29,6 +29,7 @@
import android.media.audio.common.AidlConversion;
import android.media.audiofx.AudioEffect;
import android.media.audiopolicy.AudioMix;
+import android.media.audiopolicy.AudioProductStrategy;
import android.os.Build;
import android.os.IBinder;
import android.os.Parcel;
@@ -47,6 +48,7 @@
import java.util.Map;
import java.util.Objects;
import java.util.Set;
+import java.util.TreeSet;
/* IF YOU CHANGE ANY OF THE CONSTANTS IN THIS FILE, DO NOT FORGET
* TO UPDATE THE CORRESPONDING NATIVE GLUE AND AudioManager.java.
@@ -1655,9 +1657,63 @@
/** @hide */
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public static native boolean getMasterMute();
- /** @hide */
+ /** @hide
+ * Only used (unsupported) for legacy apps.
+ * @deprecated on {@link android.os.Build.VERSION_CODES#T} as new devices
+ * will have multi-bit device types.
+ * Use {@link AudioManager#getDevicesForAttributes(AudioAttributes)} instead.
+ */
@UnsupportedAppUsage
- public static native int getDevicesForStream(int stream);
+ @Deprecated
+ public static int getDevicesForStream(int stream) {
+ final AudioAttributes attr =
+ AudioProductStrategy.getAudioAttributesForStrategyWithLegacyStreamType(stream);
+ return getDeviceMaskFromSet(generateAudioDeviceTypesSet(
+ getDevicesForAttributes(attr, true /* forVolume */)));
+ }
+
+ /** @hide
+ * Conversion from a device set to a bit mask.
+ *
+ * Legacy compatibility method (use a device list instead of a bit mask).
+ * Conversion to bit mask skips multi-bit (S and later) internal device types
+ * (e.g. AudioSystem.DEVICE_OUT* or AudioManager.DEVICE_OUT*) for legacy
+ * compatibility reasons. Legacy apps will not understand these new device types
+ * and it will raise false matches with old device types.
+ */
+ public static int getDeviceMaskFromSet(@NonNull Set<Integer> deviceSet) {
+ int deviceMask = DEVICE_NONE; // zero.
+ int deviceInChecksum = DEVICE_BIT_IN;
+ for (Integer device : deviceSet) {
+ if ((device & (device - 1) & ~DEVICE_BIT_IN) != 0) {
+ Log.v(TAG, "getDeviceMaskFromSet skipping multi-bit device value " + device);
+ continue;
+ }
+ deviceMask |= device;
+ deviceInChecksum &= device;
+ }
+ // Validate that deviceSet is either ALL input devices or ALL output devices.
+ // We check that the "OR" of all the DEVICE_BIT_INs == the "AND" of all DEVICE_BIT_INs.
+ if (!deviceSet.isEmpty() && deviceInChecksum != (deviceMask & DEVICE_BIT_IN)) {
+ Log.e(TAG, "getDeviceMaskFromSet: Invalid set: " + deviceSetToString(deviceSet));
+ }
+ return deviceMask;
+ }
+
+ /** @hide */
+ @NonNull
+ public static String deviceSetToString(@NonNull Set<Integer> devices) {
+ int n = 0;
+ StringBuilder sb = new StringBuilder();
+ for (Integer device : devices) {
+ if (n++ > 0) {
+ sb.append(", ");
+ }
+ sb.append(AudioSystem.getDeviceName(device));
+ sb.append("(" + Integer.toHexString(device) + ")");
+ }
+ return sb.toString();
+ }
/**
* @hide
@@ -2252,18 +2308,15 @@
/**
* @hide
- * Return a set of audio device types from a bit mask audio device type, which may
+ * Return a set of audio device types from a list of audio device attributes, which may
* represent multiple audio device types.
- * FIXME: Remove this when getting ride of bit mask usage of audio device types.
*/
- public static Set<Integer> generateAudioDeviceTypesSet(int types) {
- Set<Integer> deviceTypes = new HashSet<>();
- Set<Integer> allDeviceTypes =
- (types & DEVICE_BIT_IN) == 0 ? DEVICE_OUT_ALL_SET : DEVICE_IN_ALL_SET;
- for (int deviceType : allDeviceTypes) {
- if ((types & deviceType) == deviceType) {
- deviceTypes.add(deviceType);
- }
+ @NonNull
+ public static Set<Integer> generateAudioDeviceTypesSet(
+ @NonNull List<AudioDeviceAttributes> deviceList) {
+ Set<Integer> deviceTypes = new TreeSet<>();
+ for (AudioDeviceAttributes device : deviceList) {
+ deviceTypes.add(device.getInternalType());
}
return deviceTypes;
}
@@ -2274,7 +2327,7 @@
*/
public static Set<Integer> intersectionAudioDeviceTypes(
@NonNull Set<Integer> a, @NonNull Set<Integer> b) {
- Set<Integer> intersection = new HashSet<>(a);
+ Set<Integer> intersection = new TreeSet<>(a);
intersection.retainAll(b);
return intersection;
}
diff --git a/media/java/android/media/IAudioService.aidl b/media/java/android/media/IAudioService.aidl
index d702eb9..fa3057a 100755
--- a/media/java/android/media/IAudioService.aidl
+++ b/media/java/android/media/IAudioService.aidl
@@ -360,7 +360,7 @@
boolean isMusicActive(in boolean remotely);
- int getDevicesForStream(in int streamType);
+ int getDeviceMaskForStream(in int streamType);
int[] getAvailableCommunicationDeviceIds();
diff --git a/obex/Android.bp b/obex/Android.bp
index 37e7f76..d89d41d 100644
--- a/obex/Android.bp
+++ b/obex/Android.bp
@@ -44,6 +44,8 @@
],
}
+// No longer used. Only kept because the ObexPacket class is a public API.
+// The library has been migrated to platform/external/obex.
java_sdk_library {
name: "javax.obex",
srcs: ["javax/**/*.java"],
diff --git a/obex/javax/obex/ApplicationParameter.java b/obex/javax/obex/ApplicationParameter.java
deleted file mode 100644
index 16770a1a..0000000
--- a/obex/javax/obex/ApplicationParameter.java
+++ /dev/null
@@ -1,162 +0,0 @@
-/*
- * Copyright (c) 2008-2009, Motorola, Inc.
- *
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of the Motorola, Inc. nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-package javax.obex;
-
-/**
- * @hide
- */
-public final class ApplicationParameter {
-
- private byte[] mArray;
-
- private int mLength;
-
- private int mMaxLength = 1000;
-
- public static class TRIPLET_TAGID {
- public static final byte ORDER_TAGID = 0x01;
-
- public static final byte SEARCH_VALUE_TAGID = 0x02;
-
- public static final byte SEARCH_ATTRIBUTE_TAGID = 0x03;
-
- // if equals to "0", PSE only reply number of contacts
- public static final byte MAXLISTCOUNT_TAGID = 0x04;
-
- public static final byte LISTSTARTOFFSET_TAGID = 0x05;
-
- public static final byte PROPERTY_SELECTOR_TAGID = 0x06;
-
- public static final byte FORMAT_TAGID = 0x07;
-
- // only used if max list count = 0
- public static final byte PHONEBOOKSIZE_TAGID = 0x08;
-
- // only used in "mch" in response
- public static final byte NEWMISSEDCALLS_TAGID = 0x09;
-
- public static final byte SUPPORTEDFEATURE_TAGID = 0x10;
-
- public static final byte PRIMARYVERSIONCOUNTER_TAGID = 0x0A;
-
- public static final byte SECONDARYVERSIONCOUNTER_TAGID = 0x0B;
-
- public static final byte VCARDSELECTOR_TAGID = 0x0C;
-
- public static final byte DATABASEIDENTIFIER_TAGID = 0x0D;
-
- public static final byte VCARDSELECTOROPERATOR_TAGID = 0x0E;
-
- public static final byte RESET_NEW_MISSED_CALLS_TAGID = 0x0F;
- }
-
- public static class TRIPLET_VALUE {
- public static class ORDER {
- public static final byte ORDER_BY_INDEX = 0x00;
-
- public static final byte ORDER_BY_ALPHANUMERIC = 0x01;
-
- public static final byte ORDER_BY_PHONETIC = 0x02;
- }
-
- public static class SEARCHATTRIBUTE {
- public static final byte SEARCH_BY_NAME = 0x00;
-
- public static final byte SEARCH_BY_NUMBER = 0x01;
-
- public static final byte SEARCH_BY_SOUND = 0x02;
- }
-
- public static class FORMAT {
- public static final byte VCARD_VERSION_21 = 0x00;
-
- public static final byte VCARD_VERSION_30 = 0x01;
- }
- }
-
- public static class TRIPLET_LENGTH {
- public static final byte ORDER_LENGTH = 1;
-
- public static final byte SEARCH_ATTRIBUTE_LENGTH = 1;
-
- public static final byte MAXLISTCOUNT_LENGTH = 2;
-
- public static final byte LISTSTARTOFFSET_LENGTH = 2;
-
- public static final byte PROPERTY_SELECTOR_LENGTH = 8;
-
- public static final byte FORMAT_LENGTH = 1;
-
- public static final byte PHONEBOOKSIZE_LENGTH = 2;
-
- public static final byte NEWMISSEDCALLS_LENGTH = 1;
-
- public static final byte SUPPORTEDFEATURE_LENGTH = 4;
-
- public static final byte PRIMARYVERSIONCOUNTER_LENGTH = 16;
-
- public static final byte SECONDARYVERSIONCOUNTER_LENGTH = 16;
-
- public static final byte VCARDSELECTOR_LENGTH = 8;
-
- public static final byte DATABASEIDENTIFIER_LENGTH = 16;
-
- public static final byte VCARDSELECTOROPERATOR_LENGTH = 1;
-
- public static final byte RESETNEWMISSEDCALLS_LENGTH = 1;
- }
-
- public ApplicationParameter() {
- mArray = new byte[mMaxLength];
- mLength = 0;
- }
-
- public void addAPPHeader(byte tag, byte len, byte[] value) {
- if ((mLength + len + 2) > mMaxLength) {
- byte[] array_tmp = new byte[mLength + 4 * len];
- System.arraycopy(mArray, 0, array_tmp, 0, mLength);
- mArray = array_tmp;
- mMaxLength = mLength + 4 * len;
- }
- mArray[mLength++] = tag;
- mArray[mLength++] = len;
- System.arraycopy(value, 0, mArray, mLength, len);
- mLength += len;
- }
-
- public byte[] getAPPparam() {
- byte[] para = new byte[mLength];
- System.arraycopy(mArray, 0, para, 0, mLength);
- return para;
- }
-}
diff --git a/obex/javax/obex/Authenticator.java b/obex/javax/obex/Authenticator.java
deleted file mode 100644
index ec226fb..0000000
--- a/obex/javax/obex/Authenticator.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * Copyright (c) 2008-2009, Motorola, Inc.
- *
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of the Motorola, Inc. nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-package javax.obex;
-
-/**
- * This interface provides a way to respond to authentication challenge and
- * authentication response headers. When a client or server receives an
- * authentication challenge or authentication response header, the
- * <code>onAuthenticationChallenge()</code> or
- * <code>onAuthenticationResponse()</code> will be called, respectively, by the
- * implementation.
- * <P>
- * For more information on how the authentication procedure works in OBEX,
- * please review the IrOBEX specification at <A
- * HREF="http://www.irda.org">http://www.irda.org</A>.
- * <P>
- * <STRONG>Authentication Challenges</STRONG>
- * <P>
- * When a client or server receives an authentication challenge header, the
- * <code>onAuthenticationChallenge()</code> method will be invoked by the OBEX
- * API implementation. The application will then return the user name (if
- * needed) and password via a <code>PasswordAuthentication</code> object. The
- * password in this object is not sent in the authentication response. Instead,
- * the 16-byte challenge received in the authentication challenge is combined
- * with the password returned from the <code>onAuthenticationChallenge()</code>
- * method and passed through the MD5 hash algorithm. The resulting value is sent
- * in the authentication response along with the user name if it was provided.
- * <P>
- * <STRONG>Authentication Responses</STRONG>
- * <P>
- * When a client or server receives an authentication response header, the
- * <code>onAuthenticationResponse()</code> method is invoked by the API
- * implementation with the user name received in the authentication response
- * header. (The user name will be <code>null</code> if no user name was provided
- * in the authentication response header.) The application must determine the
- * correct password. This value should be returned from the
- * <code>onAuthenticationResponse()</code> method. If the authentication request
- * should fail without the implementation checking the password,
- * <code>null</code> should be returned by the application. (This is needed for
- * reasons like not recognizing the user name, etc.) If the returned value is
- * not <code>null</code>, the OBEX API implementation will combine the password
- * returned from the <code>onAuthenticationResponse()</code> method and
- * challenge sent via the authentication challenge, apply the MD5 hash
- * algorithm, and compare the result to the response hash received in the
- * authentication response header. If the values are not equal, an
- * <code>IOException</code> will be thrown if the client requested
- * authentication. If the server requested authentication, the
- * <code>onAuthenticationFailure()</code> method will be called on the
- * <code>ServerRequestHandler</code> that failed authentication. The connection
- * is <B>not</B> closed if authentication failed.
- * @hide
- */
-public interface Authenticator {
-
- /**
- * Called when a client or a server receives an authentication challenge
- * header. It should respond to the challenge with a
- * <code>PasswordAuthentication</code> that contains the correct user name
- * and password for the challenge.
- * @param description the description of which user name and password should
- * be used; if no description is provided in the authentication
- * challenge or the description is encoded in an encoding scheme that
- * is not supported, an empty string will be provided
- * @param isUserIdRequired <code>true</code> if the user ID is required;
- * <code>false</code> if the user ID is not required
- * @param isFullAccess <code>true</code> if full access to the server will
- * be granted; <code>false</code> if read only access will be granted
- * @return a <code>PasswordAuthentication</code> object containing the user
- * name and password used for authentication
- */
- PasswordAuthentication onAuthenticationChallenge(String description, boolean isUserIdRequired,
- boolean isFullAccess);
-
- /**
- * Called when a client or server receives an authentication response
- * header. This method will provide the user name and expect the correct
- * password to be returned.
- * @param userName the user name provided in the authentication response; may
- * be <code>null</code>
- * @return the correct password for the user name provided; if
- * <code>null</code> is returned then the authentication request
- * failed
- */
- byte[] onAuthenticationResponse(byte[] userName);
-}
diff --git a/obex/javax/obex/BaseStream.java b/obex/javax/obex/BaseStream.java
deleted file mode 100644
index 022ad4f..0000000
--- a/obex/javax/obex/BaseStream.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Copyright (c) 2008-2009, Motorola, Inc.
- *
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of the Motorola, Inc. nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-package javax.obex;
-
-import java.io.IOException;
-
-/**
- * This interface defines the methods needed by a parent that uses the
- * PrivateInputStream and PrivateOutputStream objects defined in this package.
- * @hide
- */
-public interface BaseStream {
-
- /**
- * Verifies that this object is still open.
- * @throws IOException if the object is closed
- */
- void ensureOpen() throws IOException;
-
- /**
- * Verifies that additional information may be sent. In other words, the
- * operation is not done.
- * @throws IOException if the operation is completed
- */
- void ensureNotDone() throws IOException;
-
- /**
- * Continues the operation since there is no data to read.
- * @param sendEmpty <code>true</code> if the operation should send an empty
- * packet or not send anything if there is no data to send
- * @param inStream <code>true</code> if the stream is input stream or is
- * output stream
- * @return <code>true</code> if the operation was completed;
- * <code>false</code> if no operation took place
- * @throws IOException if an IO error occurs
- */
- boolean continueOperation(boolean sendEmpty, boolean inStream) throws IOException;
-
- /**
- * Called when the output or input stream is closed.
- * @param inStream <code>true</code> if the input stream is closed;
- * <code>false</code> if the output stream is closed
- * @throws IOException if an IO error occurs
- */
- void streamClosed(boolean inStream) throws IOException;
-}
diff --git a/obex/javax/obex/ClientOperation.java b/obex/javax/obex/ClientOperation.java
deleted file mode 100644
index c627dfb..0000000
--- a/obex/javax/obex/ClientOperation.java
+++ /dev/null
@@ -1,851 +0,0 @@
-/*
- * Copyright (c) 2015 The Android Open Source Project
- * Copyright (C) 2015 Samsung LSI
- * Copyright (c) 2008-2009, Motorola, Inc.
- *
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of the Motorola, Inc. nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-package javax.obex;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.ByteArrayOutputStream;
-
-import android.util.Log;
-
-/**
- * This class implements the <code>Operation</code> interface. It will read and
- * write data via puts and gets.
- * @hide
- */
-public final class ClientOperation implements Operation, BaseStream {
-
- private static final String TAG = "ClientOperation";
-
- private static final boolean V = ObexHelper.VDBG;
-
- private ClientSession mParent;
-
- private boolean mInputOpen;
-
- private PrivateInputStream mPrivateInput;
-
- private boolean mPrivateInputOpen;
-
- private PrivateOutputStream mPrivateOutput;
-
- private boolean mPrivateOutputOpen;
-
- private String mExceptionMessage;
-
- private int mMaxPacketSize;
-
- private boolean mOperationDone;
-
- private boolean mGetOperation;
-
- private boolean mGetFinalFlag;
-
- private HeaderSet mRequestHeader;
-
- private HeaderSet mReplyHeader;
-
- private boolean mEndOfBodySent;
-
- private boolean mSendBodyHeader = true;
- // A latch - when triggered, there is not way back ;-)
- private boolean mSrmActive = false;
-
- // Assume SRM disabled - until support is confirmed
- // by the server
- private boolean mSrmEnabled = false;
- // keep waiting until final-bit is received in request
- // to handle the case where the SRM enable header is in
- // a different OBEX packet than the SRMP header.
- private boolean mSrmWaitingForRemote = true;
-
-
- /**
- * Creates new OperationImpl to read and write data to a server
- * @param maxSize the maximum packet size
- * @param p the parent to this object
- * @param type <code>true</code> if this is a get request;
- * <code>false</code. if this is a put request
- * @param header the header to set in the initial request
- * @throws IOException if the an IO error occurred
- */
- public ClientOperation(int maxSize, ClientSession p, HeaderSet header, boolean type)
- throws IOException {
-
- mParent = p;
- mEndOfBodySent = false;
- mInputOpen = true;
- mOperationDone = false;
- mMaxPacketSize = maxSize;
- mGetOperation = type;
- mGetFinalFlag = false;
-
- mPrivateInputOpen = false;
- mPrivateOutputOpen = false;
- mPrivateInput = null;
- mPrivateOutput = null;
-
- mReplyHeader = new HeaderSet();
-
- mRequestHeader = new HeaderSet();
-
- int[] headerList = header.getHeaderList();
-
- if (headerList != null) {
-
- for (int i = 0; i < headerList.length; i++) {
- mRequestHeader.setHeader(headerList[i], header.getHeader(headerList[i]));
- }
- }
-
- if ((header).mAuthChall != null) {
- mRequestHeader.mAuthChall = new byte[(header).mAuthChall.length];
- System.arraycopy((header).mAuthChall, 0, mRequestHeader.mAuthChall, 0,
- (header).mAuthChall.length);
- }
-
- if ((header).mAuthResp != null) {
- mRequestHeader.mAuthResp = new byte[(header).mAuthResp.length];
- System.arraycopy((header).mAuthResp, 0, mRequestHeader.mAuthResp, 0,
- (header).mAuthResp.length);
-
- }
-
- if ((header).mConnectionID != null) {
- mRequestHeader.mConnectionID = new byte[4];
- System.arraycopy((header).mConnectionID, 0, mRequestHeader.mConnectionID, 0,
- 4);
-
- }
- }
-
- /**
- * Allows to set flag which will force GET to be always sent as single packet request with
- * final flag set. This is to improve compatibility with some profiles, i.e. PBAP which
- * require requests to be sent this way.
- */
- public void setGetFinalFlag(boolean flag) {
- mGetFinalFlag = flag;
- }
-
- /**
- * Sends an ABORT message to the server. By calling this method, the
- * corresponding input and output streams will be closed along with this
- * object.
- * @throws IOException if the transaction has already ended or if an OBEX
- * server called this method
- */
- public synchronized void abort() throws IOException {
- ensureOpen();
- //no compatible with sun-ri
- if ((mOperationDone) && (mReplyHeader.responseCode != ResponseCodes.OBEX_HTTP_CONTINUE)) {
- throw new IOException("Operation has already ended");
- }
-
- mExceptionMessage = "Operation aborted";
- if ((!mOperationDone) && (mReplyHeader.responseCode == ResponseCodes.OBEX_HTTP_CONTINUE)) {
- mOperationDone = true;
- /*
- * Since we are not sending any headers or returning any headers then
- * we just need to write and read the same bytes
- */
- mParent.sendRequest(ObexHelper.OBEX_OPCODE_ABORT, null, mReplyHeader, null, false);
-
- if (mReplyHeader.responseCode != ResponseCodes.OBEX_HTTP_OK) {
- throw new IOException("Invalid response code from server");
- }
-
- mExceptionMessage = null;
- }
-
- close();
- }
-
- /**
- * Retrieves the response code retrieved from the server. Response codes are
- * defined in the <code>ResponseCodes</code> interface.
- * @return the response code retrieved from the server
- * @throws IOException if an error occurred in the transport layer during
- * the transaction; if this method is called on a
- * <code>HeaderSet</code> object created by calling
- * <code>createHeaderSet</code> in a <code>ClientSession</code>
- * object
- */
- public synchronized int getResponseCode() throws IOException {
- if ((mReplyHeader.responseCode == -1)
- || (mReplyHeader.responseCode == ResponseCodes.OBEX_HTTP_CONTINUE)) {
- validateConnection();
- }
-
- return mReplyHeader.responseCode;
- }
-
- /**
- * This method will always return <code>null</code>
- * @return <code>null</code>
- */
- public String getEncoding() {
- return null;
- }
-
- /**
- * Returns the type of content that the resource connected to is providing.
- * E.g. if the connection is via HTTP, then the value of the content-type
- * header field is returned.
- * @return the content type of the resource that the URL references, or
- * <code>null</code> if not known
- */
- public String getType() {
- try {
- return (String)mReplyHeader.getHeader(HeaderSet.TYPE);
- } catch (IOException e) {
- if(V) Log.d(TAG, "Exception occured - returning null",e);
- return null;
- }
- }
-
- /**
- * Returns the length of the content which is being provided. E.g. if the
- * connection is via HTTP, then the value of the content-length header field
- * is returned.
- * @return the content length of the resource that this connection's URL
- * references, or -1 if the content length is not known
- */
- public long getLength() {
- try {
- Long temp = (Long)mReplyHeader.getHeader(HeaderSet.LENGTH);
-
- if (temp == null) {
- return -1;
- } else {
- return temp.longValue();
- }
- } catch (IOException e) {
- if(V) Log.d(TAG,"Exception occured - returning -1",e);
- return -1;
- }
- }
-
- /**
- * Open and return an input stream for a connection.
- * @return an input stream
- * @throws IOException if an I/O error occurs
- */
- public InputStream openInputStream() throws IOException {
-
- ensureOpen();
-
- if (mPrivateInputOpen)
- throw new IOException("no more input streams available");
- if (mGetOperation) {
- // send the GET request here
- validateConnection();
- } else {
- if (mPrivateInput == null) {
- mPrivateInput = new PrivateInputStream(this);
- }
- }
-
- mPrivateInputOpen = true;
-
- return mPrivateInput;
- }
-
- /**
- * Open and return a data input stream for a connection.
- * @return an input stream
- * @throws IOException if an I/O error occurs
- */
- public DataInputStream openDataInputStream() throws IOException {
- return new DataInputStream(openInputStream());
- }
-
- /**
- * Open and return an output stream for a connection.
- * @return an output stream
- * @throws IOException if an I/O error occurs
- */
- public OutputStream openOutputStream() throws IOException {
-
- ensureOpen();
- ensureNotDone();
-
- if (mPrivateOutputOpen)
- throw new IOException("no more output streams available");
-
- if (mPrivateOutput == null) {
- // there are 3 bytes operation headers and 3 bytes body headers //
- mPrivateOutput = new PrivateOutputStream(this, getMaxPacketSize());
- }
-
- mPrivateOutputOpen = true;
-
- return mPrivateOutput;
- }
-
- public int getMaxPacketSize() {
- return mMaxPacketSize - 6 - getHeaderLength();
- }
-
- public int getHeaderLength() {
- // OPP may need it
- byte[] headerArray = ObexHelper.createHeader(mRequestHeader, false);
- return headerArray.length;
- }
-
- /**
- * Open and return a data output stream for a connection.
- * @return an output stream
- * @throws IOException if an I/O error occurs
- */
- public DataOutputStream openDataOutputStream() throws IOException {
- return new DataOutputStream(openOutputStream());
- }
-
- /**
- * Closes the connection and ends the transaction
- * @throws IOException if the operation has already ended or is closed
- */
- public void close() throws IOException {
- mInputOpen = false;
- mPrivateInputOpen = false;
- mPrivateOutputOpen = false;
- mParent.setRequestInactive();
- }
-
- /**
- * Returns the headers that have been received during the operation.
- * Modifying the object returned has no effect on the headers that are sent
- * or retrieved.
- * @return the headers received during this <code>Operation</code>
- * @throws IOException if this <code>Operation</code> has been closed
- */
- public HeaderSet getReceivedHeader() throws IOException {
- ensureOpen();
-
- return mReplyHeader;
- }
-
- /**
- * Specifies the headers that should be sent in the next OBEX message that
- * is sent.
- * @param headers the headers to send in the next message
- * @throws IOException if this <code>Operation</code> has been closed or the
- * transaction has ended and no further messages will be exchanged
- * @throws IllegalArgumentException if <code>headers</code> was not created
- * by a call to <code>ServerRequestHandler.createHeaderSet()</code>
- * @throws NullPointerException if <code>headers</code> is <code>null</code>
- */
- public void sendHeaders(HeaderSet headers) throws IOException {
- ensureOpen();
- if (mOperationDone) {
- throw new IOException("Operation has already exchanged all data");
- }
-
- if (headers == null) {
- throw new IOException("Headers may not be null");
- }
-
- int[] headerList = headers.getHeaderList();
- if (headerList != null) {
- for (int i = 0; i < headerList.length; i++) {
- mRequestHeader.setHeader(headerList[i], headers.getHeader(headerList[i]));
- }
- }
- }
-
- /**
- * Verifies that additional information may be sent. In other words, the
- * operation is not done.
- * @throws IOException if the operation is completed
- */
- public void ensureNotDone() throws IOException {
- if (mOperationDone) {
- throw new IOException("Operation has completed");
- }
- }
-
- /**
- * Verifies that the connection is open and no exceptions should be thrown.
- * @throws IOException if an exception needs to be thrown
- */
- public void ensureOpen() throws IOException {
- mParent.ensureOpen();
-
- if (mExceptionMessage != null) {
- throw new IOException(mExceptionMessage);
- }
- if (!mInputOpen) {
- throw new IOException("Operation has already ended");
- }
- }
-
- /**
- * Verifies that the connection is open and the proper data has been read.
- * @throws IOException if an IO error occurs
- */
- private void validateConnection() throws IOException {
- ensureOpen();
-
- // Make sure that a response has been recieved from remote
- // before continuing
- if (mPrivateInput == null || mReplyHeader.responseCode == -1) {
- startProcessing();
- }
- }
-
- /**
- * Sends a request to the client of the specified type.
- * This function will enable SRM and set SRM active if the server
- * response allows this.
- * @param opCode the request code to send to the client
- * @return <code>true</code> if there is more data to send;
- * <code>false</code> if there is no more data to send
- * @throws IOException if an IO error occurs
- */
- private boolean sendRequest(int opCode) throws IOException {
- boolean returnValue = false;
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- int bodyLength = -1;
- byte[] headerArray = ObexHelper.createHeader(mRequestHeader, true);
- if (mPrivateOutput != null) {
- bodyLength = mPrivateOutput.size();
- }
-
- /*
- * Determine if there is space to add a body request. At present
- * this method checks to see if there is room for at least a 17
- * byte body header. This number needs to be at least 6 so that
- * there is room for the header ID and length and the reply ID and
- * length, but it is a waste of resources if we can't send much of
- * the body.
- */
- final int MINIMUM_BODY_LENGTH = 3;
- if ((ObexHelper.BASE_PACKET_LENGTH + headerArray.length + MINIMUM_BODY_LENGTH)
- > mMaxPacketSize) {
- int end = 0;
- int start = 0;
- // split & send the headerArray in multiple packets.
-
- while (end != headerArray.length) {
- //split the headerArray
-
- end = ObexHelper.findHeaderEnd(headerArray, start, mMaxPacketSize
- - ObexHelper.BASE_PACKET_LENGTH);
- // can not split
- if (end == -1) {
- mOperationDone = true;
- abort();
- mExceptionMessage = "Header larger then can be sent in a packet";
- mInputOpen = false;
-
- if (mPrivateInput != null) {
- mPrivateInput.close();
- }
-
- if (mPrivateOutput != null) {
- mPrivateOutput.close();
- }
- throw new IOException("OBEX Packet exceeds max packet size");
- }
-
- byte[] sendHeader = new byte[end - start];
- System.arraycopy(headerArray, start, sendHeader, 0, sendHeader.length);
- if (!mParent.sendRequest(opCode, sendHeader, mReplyHeader, mPrivateInput, false)) {
- return false;
- }
-
- if (mReplyHeader.responseCode != ResponseCodes.OBEX_HTTP_CONTINUE) {
- return false;
- }
-
- start = end;
- }
-
- // Enable SRM if it should be enabled
- checkForSrm();
-
- if (bodyLength > 0) {
- return true;
- } else {
- return false;
- }
- } else {
- /* All headers will fit into a single package */
- if(mSendBodyHeader == false) {
- /* As we are not to send any body data, set the FINAL_BIT */
- opCode |= ObexHelper.OBEX_OPCODE_FINAL_BIT_MASK;
- }
- out.write(headerArray);
- }
-
- if (bodyLength > 0) {
- /*
- * Determine if we can send the whole body or just part of
- * the body. Remember that there is the 3 bytes for the
- * response message and 3 bytes for the header ID and length
- */
- if (bodyLength > (mMaxPacketSize - headerArray.length - 6)) {
- returnValue = true;
-
- bodyLength = mMaxPacketSize - headerArray.length - 6;
- }
-
- byte[] body = mPrivateOutput.readBytes(bodyLength);
-
- /*
- * Since this is a put request if the final bit is set or
- * the output stream is closed we need to send the 0x49
- * (End of Body) otherwise, we need to send 0x48 (Body)
- */
- if ((mPrivateOutput.isClosed()) && (!returnValue) && (!mEndOfBodySent)
- && ((opCode & ObexHelper.OBEX_OPCODE_FINAL_BIT_MASK) != 0)) {
- out.write(HeaderSet.END_OF_BODY);
- mEndOfBodySent = true;
- } else {
- out.write(HeaderSet.BODY);
- }
-
- bodyLength += 3;
- out.write((byte)(bodyLength >> 8));
- out.write((byte)bodyLength);
-
- if (body != null) {
- out.write(body);
- }
- }
-
- if (mPrivateOutputOpen && bodyLength <= 0 && !mEndOfBodySent) {
- // only 0x82 or 0x83 can send 0x49
- if ((opCode & ObexHelper.OBEX_OPCODE_FINAL_BIT_MASK) == 0) {
- out.write(HeaderSet.BODY);
- } else {
- out.write(HeaderSet.END_OF_BODY);
- mEndOfBodySent = true;
- }
-
- bodyLength = 3;
- out.write((byte)(bodyLength >> 8));
- out.write((byte)bodyLength);
- }
-
- if (out.size() == 0) {
- if (!mParent.sendRequest(opCode, null, mReplyHeader, mPrivateInput, mSrmActive)) {
- return false;
- }
- // Enable SRM if it should be enabled
- checkForSrm();
- return returnValue;
- }
- if ((out.size() > 0)
- && (!mParent.sendRequest(opCode, out.toByteArray(),
- mReplyHeader, mPrivateInput, mSrmActive))) {
- return false;
- }
- // Enable SRM if it should be enabled
- checkForSrm();
-
- // send all of the output data in 0x48,
- // send 0x49 with empty body
- if ((mPrivateOutput != null) && (mPrivateOutput.size() > 0))
- returnValue = true;
-
- return returnValue;
- }
-
- private void checkForSrm() throws IOException {
- Byte srmMode = (Byte)mReplyHeader.getHeader(HeaderSet.SINGLE_RESPONSE_MODE);
- if(mParent.isSrmSupported() == true && srmMode != null
- && srmMode == ObexHelper.OBEX_SRM_ENABLE) {
- mSrmEnabled = true;
- }
- /**
- * Call this only when a complete obex packet have been received.
- * (This is not optimal, but the current design is not really suited to
- * the way SRM is specified.)
- * The BT usage of SRM is not really safe - it assumes that the SRMP will fit
- * into every OBEX packet, hence if another header occupies the entire packet,
- * the scheme will not work - unlikely though.
- */
- if(mSrmEnabled) {
- mSrmWaitingForRemote = false;
- Byte srmp = (Byte)mReplyHeader.getHeader(HeaderSet.SINGLE_RESPONSE_MODE_PARAMETER);
- if(srmp != null && srmp == ObexHelper.OBEX_SRMP_WAIT) {
- mSrmWaitingForRemote = true;
- // Clear the wait header, as the absence of the header in the next packet
- // indicates don't wait anymore.
- mReplyHeader.setHeader(HeaderSet.SINGLE_RESPONSE_MODE_PARAMETER, null);
- }
- }
- if((mSrmWaitingForRemote == false) && (mSrmEnabled == true)) {
- mSrmActive = true;
- }
- }
-
- /**
- * This method starts the processing thread results. It will send the
- * initial request. If the response takes more then one packet, a thread
- * will be started to handle additional requests
- * @throws IOException if an IO error occurs
- */
- private synchronized void startProcessing() throws IOException {
-
- if (mPrivateInput == null) {
- mPrivateInput = new PrivateInputStream(this);
- }
- boolean more = true;
-
- if (mGetOperation) {
- if (!mOperationDone) {
- if (!mGetFinalFlag) {
- mReplyHeader.responseCode = ResponseCodes.OBEX_HTTP_CONTINUE;
- while ((more) && (mReplyHeader.responseCode ==
- ResponseCodes.OBEX_HTTP_CONTINUE)) {
- more = sendRequest(ObexHelper.OBEX_OPCODE_GET);
- }
- // For GET we need to loop until all headers have been sent,
- // And then we wait for the first continue package with the
- // reply.
- if (mReplyHeader.responseCode == ResponseCodes.OBEX_HTTP_CONTINUE) {
- mParent.sendRequest(ObexHelper.OBEX_OPCODE_GET_FINAL,
- null, mReplyHeader, mPrivateInput, mSrmActive);
- }
- if (mReplyHeader.responseCode != ResponseCodes.OBEX_HTTP_CONTINUE) {
- mOperationDone = true;
- } else {
- checkForSrm();
- }
- } else {
- more = sendRequest(ObexHelper.OBEX_OPCODE_GET_FINAL);
-
- if (more) {
- throw new IOException("FINAL_GET forced, data didn't fit into one packet");
- }
-
- mOperationDone = true;
- }
- }
- } else {
- // PUT operation
- if (!mOperationDone) {
- mReplyHeader.responseCode = ResponseCodes.OBEX_HTTP_CONTINUE;
- while ((more) && (mReplyHeader.responseCode == ResponseCodes.OBEX_HTTP_CONTINUE)) {
- more = sendRequest(ObexHelper.OBEX_OPCODE_PUT);
- }
- }
-
- if (mReplyHeader.responseCode == ResponseCodes.OBEX_HTTP_CONTINUE) {
- mParent.sendRequest(ObexHelper.OBEX_OPCODE_PUT_FINAL,
- null, mReplyHeader, mPrivateInput, mSrmActive);
- }
-
- if (mReplyHeader.responseCode != ResponseCodes.OBEX_HTTP_CONTINUE) {
- mOperationDone = true;
- }
- }
- }
-
- /**
- * Continues the operation since there is no data to read.
- * @param sendEmpty <code>true</code> if the operation should send an empty
- * packet or not send anything if there is no data to send
- * @param inStream <code>true</code> if the stream is input stream or is
- * output stream
- * @throws IOException if an IO error occurs
- */
- public synchronized boolean continueOperation(boolean sendEmpty, boolean inStream)
- throws IOException {
-
- // One path to the first put operation - the other one does not need to
- // handle SRM, as all will fit into one packet.
-
- if (mGetOperation) {
- if ((inStream) && (!mOperationDone)) {
- // to deal with inputstream in get operation
- mParent.sendRequest(ObexHelper.OBEX_OPCODE_GET_FINAL,
- null, mReplyHeader, mPrivateInput, mSrmActive);
- /*
- * Determine if that was not the last packet in the operation
- */
- if (mReplyHeader.responseCode != ResponseCodes.OBEX_HTTP_CONTINUE) {
- mOperationDone = true;
- } else {
- checkForSrm();
- }
-
- return true;
-
- } else if ((!inStream) && (!mOperationDone)) {
- // to deal with outputstream in get operation
-
- if (mPrivateInput == null) {
- mPrivateInput = new PrivateInputStream(this);
- }
-
- if (!mGetFinalFlag) {
- sendRequest(ObexHelper.OBEX_OPCODE_GET);
- } else {
- sendRequest(ObexHelper.OBEX_OPCODE_GET_FINAL);
- }
- if (mReplyHeader.responseCode != ResponseCodes.OBEX_HTTP_CONTINUE) {
- mOperationDone = true;
- }
- return true;
-
- } else if (mOperationDone) {
- return false;
- }
-
- } else {
- // PUT operation
- if ((!inStream) && (!mOperationDone)) {
- // to deal with outputstream in put operation
- if (mReplyHeader.responseCode == -1) {
- mReplyHeader.responseCode = ResponseCodes.OBEX_HTTP_CONTINUE;
- }
- sendRequest(ObexHelper.OBEX_OPCODE_PUT);
- return true;
- } else if ((inStream) && (!mOperationDone)) {
- // How to deal with inputstream in put operation ?
- return false;
-
- } else if (mOperationDone) {
- return false;
- }
-
- }
- return false;
- }
-
- /**
- * Called when the output or input stream is closed.
- * @param inStream <code>true</code> if the input stream is closed;
- * <code>false</code> if the output stream is closed
- * @throws IOException if an IO error occurs
- */
- public void streamClosed(boolean inStream) throws IOException {
- if (!mGetOperation) {
- if ((!inStream) && (!mOperationDone)) {
- // to deal with outputstream in put operation
-
- boolean more = true;
-
- if ((mPrivateOutput != null) && (mPrivateOutput.size() <= 0)) {
- byte[] headerArray = ObexHelper.createHeader(mRequestHeader, false);
- if (headerArray.length <= 0)
- more = false;
- }
- // If have not sent any data so send all now
- if (mReplyHeader.responseCode == -1) {
- mReplyHeader.responseCode = ResponseCodes.OBEX_HTTP_CONTINUE;
- }
-
- while ((more) && (mReplyHeader.responseCode == ResponseCodes.OBEX_HTTP_CONTINUE)) {
- more = sendRequest(ObexHelper.OBEX_OPCODE_PUT);
- }
-
- /*
- * According to the IrOBEX specification, after the final put, you
- * only have a single reply to send. so we don't need the while
- * loop.
- */
- while (mReplyHeader.responseCode == ResponseCodes.OBEX_HTTP_CONTINUE) {
-
- sendRequest(ObexHelper.OBEX_OPCODE_PUT_FINAL);
- }
- mOperationDone = true;
- } else if ((inStream) && (mOperationDone)) {
- // how to deal with input stream in put stream ?
- mOperationDone = true;
- }
- } else {
- if ((inStream) && (!mOperationDone)) {
-
- // to deal with inputstream in get operation
- // Have not sent any data so send it all now
-
- if (mReplyHeader.responseCode == -1) {
- mReplyHeader.responseCode = ResponseCodes.OBEX_HTTP_CONTINUE;
- }
-
- while (mReplyHeader.responseCode == ResponseCodes.OBEX_HTTP_CONTINUE && !mOperationDone) {
- if (!sendRequest(ObexHelper.OBEX_OPCODE_GET_FINAL)) {
- break;
- }
- }
- while (mReplyHeader.responseCode == ResponseCodes.OBEX_HTTP_CONTINUE && !mOperationDone) {
- mParent.sendRequest(ObexHelper.OBEX_OPCODE_GET_FINAL, null,
- mReplyHeader, mPrivateInput, false);
- // Regardless of the SRM state, wait for the response.
- }
- mOperationDone = true;
- } else if ((!inStream) && (!mOperationDone)) {
- // to deal with outputstream in get operation
- // part of the data may have been sent in continueOperation.
-
- boolean more = true;
-
- if ((mPrivateOutput != null) && (mPrivateOutput.size() <= 0)) {
- byte[] headerArray = ObexHelper.createHeader(mRequestHeader, false);
- if (headerArray.length <= 0)
- more = false;
- }
-
- if (mPrivateInput == null) {
- mPrivateInput = new PrivateInputStream(this);
- }
- if ((mPrivateOutput != null) && (mPrivateOutput.size() <= 0))
- more = false;
-
- mReplyHeader.responseCode = ResponseCodes.OBEX_HTTP_CONTINUE;
- while ((more) && (mReplyHeader.responseCode == ResponseCodes.OBEX_HTTP_CONTINUE)) {
- more = sendRequest(ObexHelper.OBEX_OPCODE_GET);
- }
- sendRequest(ObexHelper.OBEX_OPCODE_GET_FINAL);
- // parent.sendRequest(0x83, null, replyHeaders, privateInput);
- if (mReplyHeader.responseCode != ResponseCodes.OBEX_HTTP_CONTINUE) {
- mOperationDone = true;
- }
- }
- }
- }
-
- public void noBodyHeader(){
- mSendBodyHeader = false;
- }
-}
diff --git a/obex/javax/obex/ClientSession.java b/obex/javax/obex/ClientSession.java
deleted file mode 100644
index 272a920..0000000
--- a/obex/javax/obex/ClientSession.java
+++ /dev/null
@@ -1,616 +0,0 @@
-/*
- * Copyright (c) 2015 The Android Open Source Project
- * Copyright (C) 2015 Samsung LSI
- * Copyright (c) 2008-2009, Motorola, Inc.
- *
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of the Motorola, Inc. nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-package javax.obex;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-
-import android.util.Log;
-
-/**
- * This class in an implementation of the OBEX ClientSession.
- * @hide
- */
-public final class ClientSession extends ObexSession {
-
- private static final String TAG = "ClientSession";
-
- private boolean mOpen;
-
- // Determines if an OBEX layer connection has been established
- private boolean mObexConnected;
-
- private byte[] mConnectionId = null;
-
- /*
- * The max Packet size must be at least 255 according to the OBEX
- * specification.
- */
- private int mMaxTxPacketSize = ObexHelper.LOWER_LIMIT_MAX_PACKET_SIZE;
-
- private boolean mRequestActive;
-
- private final InputStream mInput;
-
- private final OutputStream mOutput;
-
- private final boolean mLocalSrmSupported;
-
- private final ObexTransport mTransport;
-
- public ClientSession(final ObexTransport trans) throws IOException {
- mInput = trans.openInputStream();
- mOutput = trans.openOutputStream();
- mOpen = true;
- mRequestActive = false;
- mLocalSrmSupported = trans.isSrmSupported();
- mTransport = trans;
- }
-
- /**
- * Create a ClientSession
- * @param trans The transport to use for OBEX transactions
- * @param supportsSrm True if Single Response Mode should be used e.g. if the
- * supplied transport is a TCP or l2cap channel.
- * @throws IOException if it occurs while opening the transport streams.
- */
- public ClientSession(final ObexTransport trans, final boolean supportsSrm) throws IOException {
- mInput = trans.openInputStream();
- mOutput = trans.openOutputStream();
- mOpen = true;
- mRequestActive = false;
- mLocalSrmSupported = supportsSrm;
- mTransport = trans;
- }
-
- public HeaderSet connect(final HeaderSet header) throws IOException {
- ensureOpen();
- if (mObexConnected) {
- throw new IOException("Already connected to server");
- }
- setRequestActive();
-
- int totalLength = 4;
- byte[] head = null;
-
- // Determine the header byte array
- if (header != null) {
- if (header.nonce != null) {
- mChallengeDigest = new byte[16];
- System.arraycopy(header.nonce, 0, mChallengeDigest, 0, 16);
- }
- head = ObexHelper.createHeader(header, false);
- totalLength += head.length;
- }
- /*
- * Write the OBEX CONNECT packet to the server.
- * Byte 0: 0x80
- * Byte 1&2: Connect Packet Length
- * Byte 3: OBEX Version Number (Presently, 0x10)
- * Byte 4: Flags (For TCP 0x00)
- * Byte 5&6: Max OBEX Packet Length (Defined in MAX_PACKET_SIZE)
- * Byte 7 to n: headers
- */
- byte[] requestPacket = new byte[totalLength];
- int maxRxPacketSize = ObexHelper.getMaxRxPacketSize(mTransport);
- // We just need to start at byte 3 since the sendRequest() method will
- // handle the length and 0x80.
- requestPacket[0] = (byte)0x10;
- requestPacket[1] = (byte)0x00;
- requestPacket[2] = (byte)(maxRxPacketSize >> 8);
- requestPacket[3] = (byte)(maxRxPacketSize & 0xFF);
- if (head != null) {
- System.arraycopy(head, 0, requestPacket, 4, head.length);
- }
-
- // Since we are not yet connected, the peer max packet size is unknown,
- // hence we are only guaranteed the server will use the first 7 bytes.
- if ((requestPacket.length + 3) > ObexHelper.MAX_PACKET_SIZE_INT) {
- throw new IOException("Packet size exceeds max packet size for connect");
- }
-
- HeaderSet returnHeaderSet = new HeaderSet();
- sendRequest(ObexHelper.OBEX_OPCODE_CONNECT, requestPacket, returnHeaderSet, null, false);
-
- /*
- * Read the response from the OBEX server.
- * Byte 0: Response Code (If successful then OBEX_HTTP_OK)
- * Byte 1&2: Packet Length
- * Byte 3: OBEX Version Number
- * Byte 4: Flags3
- * Byte 5&6: Max OBEX packet Length
- * Byte 7 to n: Optional HeaderSet
- */
- if (returnHeaderSet.responseCode == ResponseCodes.OBEX_HTTP_OK) {
- mObexConnected = true;
- }
- setRequestInactive();
-
- return returnHeaderSet;
- }
-
- public Operation get(HeaderSet header) throws IOException {
-
- if (!mObexConnected) {
- throw new IOException("Not connected to the server");
- }
- setRequestActive();
-
- ensureOpen();
-
- HeaderSet head;
- if (header == null) {
- head = new HeaderSet();
- } else {
- head = header;
- if (head.nonce != null) {
- mChallengeDigest = new byte[16];
- System.arraycopy(head.nonce, 0, mChallengeDigest, 0, 16);
- }
- }
- // Add the connection ID if one exists
- if (mConnectionId != null) {
- head.mConnectionID = new byte[4];
- System.arraycopy(mConnectionId, 0, head.mConnectionID, 0, 4);
- }
-
- if(mLocalSrmSupported) {
- head.setHeader(HeaderSet.SINGLE_RESPONSE_MODE, ObexHelper.OBEX_SRM_ENABLE);
- /* TODO: Consider creating an interface to get the wait state.
- * On an android system, I cannot see when this is to be used.
- * except perhaps if we are to wait for user accept on a push message.
- if(getLocalWaitState()) {
- head.setHeader(HeaderSet.SINGLE_RESPONSE_MODE_PARAMETER, ObexHelper.OBEX_SRMP_WAIT);
- }
- */
- }
-
- return new ClientOperation(mMaxTxPacketSize, this, head, true);
- }
-
- /**
- * 0xCB Connection Id an identifier used for OBEX connection multiplexing
- */
- public void setConnectionID(long id) {
- if ((id < 0) || (id > 0xFFFFFFFFL)) {
- throw new IllegalArgumentException("Connection ID is not in a valid range");
- }
- mConnectionId = ObexHelper.convertToByteArray(id);
- }
-
- public HeaderSet delete(HeaderSet header) throws IOException {
-
- Operation op = put(header);
- op.getResponseCode();
- HeaderSet returnValue = op.getReceivedHeader();
- op.close();
-
- return returnValue;
- }
-
- public HeaderSet disconnect(HeaderSet header) throws IOException {
- if (!mObexConnected) {
- throw new IOException("Not connected to the server");
- }
- setRequestActive();
-
- ensureOpen();
- // Determine the header byte array
- byte[] head = null;
- if (header != null) {
- if (header.nonce != null) {
- mChallengeDigest = new byte[16];
- System.arraycopy(header.nonce, 0, mChallengeDigest, 0, 16);
- }
- // Add the connection ID if one exists
- if (mConnectionId != null) {
- header.mConnectionID = new byte[4];
- System.arraycopy(mConnectionId, 0, header.mConnectionID, 0, 4);
- }
- head = ObexHelper.createHeader(header, false);
-
- if ((head.length + 3) > mMaxTxPacketSize) {
- throw new IOException("Packet size exceeds max packet size");
- }
- } else {
- // Add the connection ID if one exists
- if (mConnectionId != null) {
- head = new byte[5];
- head[0] = (byte)HeaderSet.CONNECTION_ID;
- System.arraycopy(mConnectionId, 0, head, 1, 4);
- }
- }
-
- HeaderSet returnHeaderSet = new HeaderSet();
- sendRequest(ObexHelper.OBEX_OPCODE_DISCONNECT, head, returnHeaderSet, null, false);
-
- /*
- * An OBEX DISCONNECT reply from the server:
- * Byte 1: Response code
- * Bytes 2 & 3: packet size
- * Bytes 4 & up: headers
- */
-
- /* response code , and header are ignored
- * */
-
- synchronized (this) {
- mObexConnected = false;
- setRequestInactive();
- }
-
- return returnHeaderSet;
- }
-
- public long getConnectionID() {
-
- if (mConnectionId == null) {
- return -1;
- }
- return ObexHelper.convertToLong(mConnectionId);
- }
-
- public Operation put(HeaderSet header) throws IOException {
- if (!mObexConnected) {
- throw new IOException("Not connected to the server");
- }
- setRequestActive();
-
- ensureOpen();
- HeaderSet head;
- if (header == null) {
- head = new HeaderSet();
- } else {
- head = header;
- // when auth is initiated by client ,save the digest
- if (head.nonce != null) {
- mChallengeDigest = new byte[16];
- System.arraycopy(head.nonce, 0, mChallengeDigest, 0, 16);
- }
- }
-
- // Add the connection ID if one exists
- if (mConnectionId != null) {
-
- head.mConnectionID = new byte[4];
- System.arraycopy(mConnectionId, 0, head.mConnectionID, 0, 4);
- }
-
- if(mLocalSrmSupported) {
- head.setHeader(HeaderSet.SINGLE_RESPONSE_MODE, ObexHelper.OBEX_SRM_ENABLE);
- /* TODO: Consider creating an interface to get the wait state.
- * On an android system, I cannot see when this is to be used.
- if(getLocalWaitState()) {
- head.setHeader(HeaderSet.SINGLE_RESPONSE_MODE_PARAMETER, ObexHelper.OBEX_SRMP_WAIT);
- }
- */
- }
- return new ClientOperation(mMaxTxPacketSize, this, head, false);
- }
-
- public void setAuthenticator(Authenticator auth) throws IOException {
- if (auth == null) {
- throw new IOException("Authenticator may not be null");
- }
- mAuthenticator = auth;
- }
-
- public HeaderSet setPath(HeaderSet header, boolean backup, boolean create) throws IOException {
- if (!mObexConnected) {
- throw new IOException("Not connected to the server");
- }
- setRequestActive();
- ensureOpen();
-
- int totalLength = 2;
- byte[] head = null;
- HeaderSet headset;
- if (header == null) {
- headset = new HeaderSet();
- } else {
- headset = header;
- if (headset.nonce != null) {
- mChallengeDigest = new byte[16];
- System.arraycopy(headset.nonce, 0, mChallengeDigest, 0, 16);
- }
- }
-
- // when auth is initiated by client ,save the digest
- if (headset.nonce != null) {
- mChallengeDigest = new byte[16];
- System.arraycopy(headset.nonce, 0, mChallengeDigest, 0, 16);
- }
-
- // Add the connection ID if one exists
- if (mConnectionId != null) {
- headset.mConnectionID = new byte[4];
- System.arraycopy(mConnectionId, 0, headset.mConnectionID, 0, 4);
- }
-
- head = ObexHelper.createHeader(headset, false);
- totalLength += head.length;
-
- if (totalLength > mMaxTxPacketSize) {
- throw new IOException("Packet size exceeds max packet size");
- }
-
- int flags = 0;
- /*
- * The backup flag bit is bit 0 so if we add 1, this will set that bit
- */
- if (backup) {
- flags++;
- }
- /*
- * The create bit is bit 1 so if we or with 2 the bit will be set.
- */
- if (!create) {
- flags |= 2;
- }
-
- /*
- * An OBEX SETPATH packet to the server:
- * Byte 1: 0x85
- * Byte 2 & 3: packet size
- * Byte 4: flags
- * Byte 5: constants
- * Byte 6 & up: headers
- */
- byte[] packet = new byte[totalLength];
- packet[0] = (byte)flags;
- packet[1] = (byte)0x00;
- if (headset != null) {
- System.arraycopy(head, 0, packet, 2, head.length);
- }
-
- HeaderSet returnHeaderSet = new HeaderSet();
- sendRequest(ObexHelper.OBEX_OPCODE_SETPATH, packet, returnHeaderSet, null, false);
-
- /*
- * An OBEX SETPATH reply from the server:
- * Byte 1: Response code
- * Bytes 2 & 3: packet size
- * Bytes 4 & up: headers
- */
-
- setRequestInactive();
-
- return returnHeaderSet;
- }
-
- /**
- * Verifies that the connection is open.
- * @throws IOException if the connection is closed
- */
- public synchronized void ensureOpen() throws IOException {
- if (!mOpen) {
- throw new IOException("Connection closed");
- }
- }
-
- /**
- * Set request inactive. Allows Put and get operation objects to tell this
- * object when they are done.
- */
- /*package*/synchronized void setRequestInactive() {
- mRequestActive = false;
- }
-
- /**
- * Set request to active.
- * @throws IOException if already active
- */
- private synchronized void setRequestActive() throws IOException {
- if (mRequestActive) {
- throw new IOException("OBEX request is already being performed");
- }
- mRequestActive = true;
- }
-
- /**
- * Sends a standard request to the client. It will then wait for the reply
- * and update the header set object provided. If any authentication headers
- * (i.e. authentication challenge or authentication response) are received,
- * they will be processed.
- * @param opCode the type of request to send to the client
- * @param head the headers to send to the client
- * @param header the header object to update with the response
- * @param privateInput the input stream used by the Operation object; null
- * if this is called on a CONNECT, SETPATH or DISCONNECT
- * @return
- * <code>true</code> if the operation completed successfully;
- * <code>false</code> if an authentication response failed to pass
- * @throws IOException if an IO error occurs
- */
- public boolean sendRequest(int opCode, byte[] head, HeaderSet header,
- PrivateInputStream privateInput, boolean srmActive) throws IOException {
- //check header length with local max size
- if (head != null) {
- if ((head.length + 3) > ObexHelper.MAX_PACKET_SIZE_INT) {
- // TODO: This is an implementation limit - not a specification requirement.
- throw new IOException("header too large ");
- }
- }
-
- boolean skipSend = false;
- boolean skipReceive = false;
- if (srmActive == true) {
- if (opCode == ObexHelper.OBEX_OPCODE_PUT) {
- // we are in the middle of a SRM PUT operation, don't expect a continue.
- skipReceive = true;
- } else if (opCode == ObexHelper.OBEX_OPCODE_GET) {
- // We are still sending the get request, send, but don't expect continue
- // until the request is transfered (the final bit is set)
- skipReceive = true;
- } else if (opCode == ObexHelper.OBEX_OPCODE_GET_FINAL) {
- // All done sending the request, expect data from the server, without
- // sending continue.
- skipSend = true;
- }
-
- }
-
- int bytesReceived;
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- out.write((byte)opCode);
-
- // Determine if there are any headers to send
- if (head == null) {
- out.write(0x00);
- out.write(0x03);
- } else {
- out.write((byte)((head.length + 3) >> 8));
- out.write((byte)(head.length + 3));
- out.write(head);
- }
-
- if (!skipSend) {
- // Write the request to the output stream and flush the stream
- mOutput.write(out.toByteArray());
- // TODO: is this really needed? if this flush is implemented
- // correctly, we will get a gap between each obex packet.
- // which is kind of the idea behind SRM to avoid.
- // Consider offloading to another thread (async action)
- mOutput.flush();
- }
-
- if (!skipReceive) {
- header.responseCode = mInput.read();
-
- int length = ((mInput.read() << 8) | (mInput.read()));
-
- if (length > ObexHelper.getMaxRxPacketSize(mTransport)) {
- throw new IOException("Packet received exceeds packet size limit");
- }
- if (length > ObexHelper.BASE_PACKET_LENGTH) {
- byte[] data = null;
- if (opCode == ObexHelper.OBEX_OPCODE_CONNECT) {
- @SuppressWarnings("unused")
- int version = mInput.read();
- @SuppressWarnings("unused")
- int flags = mInput.read();
- mMaxTxPacketSize = (mInput.read() << 8) + mInput.read();
-
- //check with local max size
- if (mMaxTxPacketSize > ObexHelper.MAX_CLIENT_PACKET_SIZE) {
- mMaxTxPacketSize = ObexHelper.MAX_CLIENT_PACKET_SIZE;
- }
-
- // check with transport maximum size
- if(mMaxTxPacketSize > ObexHelper.getMaxTxPacketSize(mTransport)) {
- // To increase this size, increase the buffer size in L2CAP layer
- // in Bluedroid.
- Log.w(TAG, "An OBEX packet size of " + mMaxTxPacketSize + "was"
- + " requested. Transport only allows: "
- + ObexHelper.getMaxTxPacketSize(mTransport)
- + " Lowering limit to this value.");
- mMaxTxPacketSize = ObexHelper.getMaxTxPacketSize(mTransport);
- }
-
- if (length > 7) {
- data = new byte[length - 7];
-
- bytesReceived = mInput.read(data);
- while (bytesReceived != (length - 7)) {
- bytesReceived += mInput.read(data, bytesReceived, data.length
- - bytesReceived);
- }
- } else {
- return true;
- }
- } else {
- data = new byte[length - 3];
- bytesReceived = mInput.read(data);
-
- while (bytesReceived != (length - 3)) {
- bytesReceived += mInput.read(data, bytesReceived, data.length - bytesReceived);
- }
- if (opCode == ObexHelper.OBEX_OPCODE_ABORT) {
- return true;
- }
- }
-
- byte[] body = ObexHelper.updateHeaderSet(header, data);
- if ((privateInput != null) && (body != null)) {
- privateInput.writeBytes(body, 1);
- }
-
- if (header.mConnectionID != null) {
- mConnectionId = new byte[4];
- System.arraycopy(header.mConnectionID, 0, mConnectionId, 0, 4);
- }
-
- if (header.mAuthResp != null) {
- if (!handleAuthResp(header.mAuthResp)) {
- setRequestInactive();
- throw new IOException("Authentication Failed");
- }
- }
-
- if ((header.responseCode == ResponseCodes.OBEX_HTTP_UNAUTHORIZED)
- && (header.mAuthChall != null)) {
-
- if (handleAuthChall(header)) {
- out.write((byte)HeaderSet.AUTH_RESPONSE);
- out.write((byte)((header.mAuthResp.length + 3) >> 8));
- out.write((byte)(header.mAuthResp.length + 3));
- out.write(header.mAuthResp);
- header.mAuthChall = null;
- header.mAuthResp = null;
-
- byte[] sendHeaders = new byte[out.size() - 3];
- System.arraycopy(out.toByteArray(), 3, sendHeaders, 0, sendHeaders.length);
-
- return sendRequest(opCode, sendHeaders, header, privateInput, false);
- }
- }
- }
- }
-
- return true;
- }
-
- public void close() throws IOException {
- mOpen = false;
- mInput.close();
- mOutput.close();
- }
-
- public boolean isSrmSupported() {
- return mLocalSrmSupported;
- }
-}
diff --git a/obex/javax/obex/HeaderSet.java b/obex/javax/obex/HeaderSet.java
deleted file mode 100644
index 35fe186..0000000
--- a/obex/javax/obex/HeaderSet.java
+++ /dev/null
@@ -1,710 +0,0 @@
-/*
- * Copyright (c) 2014 The Android Open Source Project
- * Copyright (c) 2008-2009, Motorola, Inc.
- *
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of the Motorola, Inc. nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-package javax.obex;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.util.Calendar;
-import java.security.SecureRandom;
-
-/**
- * This class implements the javax.obex.HeaderSet interface for OBEX over
- * RFCOMM or OBEX over l2cap.
- * @hide
- */
-public final class HeaderSet {
-
- /**
- * Represents the OBEX Count header. This allows the connection statement to
- * tell the server how many objects it plans to send or retrieve.
- * <P>
- * The value of <code>COUNT</code> is 0xC0 (192).
- */
- public static final int COUNT = 0xC0;
-
- /**
- * Represents the OBEX Name header. This specifies the name of the object.
- * <P>
- * The value of <code>NAME</code> is 0x01 (1).
- */
- public static final int NAME = 0x01;
-
- /**
- * Represents the OBEX Type header. This allows a request to specify the
- * type of the object (e.g. text, html, binary, etc.).
- * <P>
- * The value of <code>TYPE</code> is 0x42 (66).
- */
- public static final int TYPE = 0x42;
-
- /**
- * Represents the OBEX Length header. This is the length of the object in
- * bytes.
- * <P>
- * The value of <code>LENGTH</code> is 0xC3 (195).
- */
- public static final int LENGTH = 0xC3;
-
- /**
- * Represents the OBEX Time header using the ISO 8601 standards. This is the
- * preferred time header.
- * <P>
- * The value of <code>TIME_ISO_8601</code> is 0x44 (68).
- */
- public static final int TIME_ISO_8601 = 0x44;
-
- /**
- * Represents the OBEX Time header using the 4 byte representation. This is
- * only included for backwards compatibility. It represents the number of
- * seconds since January 1, 1970.
- * <P>
- * The value of <code>TIME_4_BYTE</code> is 0xC4 (196).
- */
- public static final int TIME_4_BYTE = 0xC4;
-
- /**
- * Represents the OBEX Description header. This is a text description of the
- * object.
- * <P>
- * The value of <code>DESCRIPTION</code> is 0x05 (5).
- */
- public static final int DESCRIPTION = 0x05;
-
- /**
- * Represents the OBEX Target header. This is the name of the service an
- * operation is targeted to.
- * <P>
- * The value of <code>TARGET</code> is 0x46 (70).
- */
- public static final int TARGET = 0x46;
-
- /**
- * Represents the OBEX HTTP header. This allows an HTTP 1.X header to be
- * included in a request or reply.
- * <P>
- * The value of <code>HTTP</code> is 0x47 (71).
- */
- public static final int HTTP = 0x47;
-
- /**
- * Represents the OBEX BODY header.
- * <P>
- * The value of <code>BODY</code> is 0x48 (72).
- */
- public static final int BODY = 0x48;
-
- /**
- * Represents the OBEX End of BODY header.
- * <P>
- * The value of <code>BODY</code> is 0x49 (73).
- */
- public static final int END_OF_BODY = 0x49;
-
- /**
- * Represents the OBEX Who header. Identifies the OBEX application to
- * determine if the two peers are talking to each other.
- * <P>
- * The value of <code>WHO</code> is 0x4A (74).
- */
- public static final int WHO = 0x4A;
-
- /**
- * Represents the OBEX Connection ID header. Identifies used for OBEX
- * connection multiplexing.
- * <P>
- * The value of <code>CONNECTION_ID</code> is 0xCB (203).
- */
-
- public static final int CONNECTION_ID = 0xCB;
-
- /**
- * Represents the OBEX Application Parameter header. This header specifies
- * additional application request and response information.
- * <P>
- * The value of <code>APPLICATION_PARAMETER</code> is 0x4C (76).
- */
- public static final int APPLICATION_PARAMETER = 0x4C;
-
- /**
- * Represents the OBEX authentication digest-challenge.
- * <P>
- * The value of <code>AUTH_CHALLENGE</code> is 0x4D (77).
- */
- public static final int AUTH_CHALLENGE = 0x4D;
-
- /**
- * Represents the OBEX authentication digest-response.
- * <P>
- * The value of <code>AUTH_RESPONSE</code> is 0x4E (78).
- */
- public static final int AUTH_RESPONSE = 0x4E;
-
- /**
- * Represents the OBEX Object Class header. This header specifies the OBEX
- * object class of the object.
- * <P>
- * The value of <code>OBJECT_CLASS</code> is 0x4F (79).
- */
- public static final int OBJECT_CLASS = 0x4F;
-
- /**
- * Represents the OBEX Single Response Mode (SRM). This header is used
- * for Single response mode, introduced in OBEX 1.5.
- * <P>
- * The value of <code>SINGLE_RESPONSE_MODE</code> is 0x97 (151).
- */
- public static final int SINGLE_RESPONSE_MODE = 0x97;
-
- /**
- * Represents the OBEX Single Response Mode Parameters. This header is used
- * for Single response mode, introduced in OBEX 1.5.
- * <P>
- * The value of <code>SINGLE_RESPONSE_MODE_PARAMETER</code> is 0x98 (152).
- */
- public static final int SINGLE_RESPONSE_MODE_PARAMETER = 0x98;
-
- private Long mCount; // 4 byte unsigned integer
-
- private String mName; // null terminated Unicode text string
-
- private boolean mEmptyName;
-
- private String mType; // null terminated ASCII text string
-
- private Long mLength; // 4 byte unsigend integer
-
- private Calendar mIsoTime; // String of the form YYYYMMDDTHHMMSSZ
-
- private Calendar mByteTime; // 4 byte unsigned integer
-
- private String mDescription; // null terminated Unicode text String
-
- private byte[] mTarget; // byte sequence
-
- private byte[] mHttpHeader; // byte sequence
-
- private byte[] mWho; // length prefixed byte sequence
-
- private byte[] mAppParam; // byte sequence of the form tag length value
-
- private byte[] mObjectClass; // byte sequence
-
- private String[] mUnicodeUserDefined; // null terminated unicode string
-
- private byte[][] mSequenceUserDefined; // byte sequence user defined
-
- private Byte[] mByteUserDefined; // 1 byte
-
- private Long[] mIntegerUserDefined; // 4 byte unsigned integer
-
- private SecureRandom mRandom = null;
-
- private Byte mSingleResponseMode; // byte to indicate enable/disable/support for SRM
-
- private Byte mSrmParam; // byte representing the SRM parameters - only "wait"
- // is supported by Bluetooth
-
- /*package*/ byte[] nonce;
-
- public byte[] mAuthChall; // The authentication challenge header
-
- public byte[] mAuthResp; // The authentication response header
-
- public byte[] mConnectionID; // THe connection ID
-
- public int responseCode;
-
- /**
- * Creates new <code>HeaderSet</code> object.
- * @param size the max packet size for this connection
- */
- public HeaderSet() {
- mUnicodeUserDefined = new String[16];
- mSequenceUserDefined = new byte[16][];
- mByteUserDefined = new Byte[16];
- mIntegerUserDefined = new Long[16];
- responseCode = -1;
- }
-
- /**
- * Sets flag for special "value" of NAME header which should be empty. This
- * is not the same as NAME header with empty string in which case it will
- * have length of 5 bytes. It should be 3 bytes with only header id and
- * length field.
- */
- public void setEmptyNameHeader() {
- mName = null;
- mEmptyName = true;
- }
-
- /**
- * Gets flag for special "value" of NAME header which should be empty. See
- * above.
- */
- public boolean getEmptyNameHeader() {
- return mEmptyName;
- }
-
- /**
- * Sets the value of the header identifier to the value provided. The type
- * of object must correspond to the Java type defined in the description of
- * this interface. If <code>null</code> is passed as the
- * <code>headerValue</code> then the header will be removed from the set of
- * headers to include in the next request.
- * @param headerID the identifier to include in the message
- * @param headerValue the value of the header identifier
- * @throws IllegalArgumentException if the header identifier provided is not
- * one defined in this interface or a user-defined header; if the
- * type of <code>headerValue</code> is not the correct Java type as
- * defined in the description of this interface\
- */
- public void setHeader(int headerID, Object headerValue) {
- long temp = -1;
-
- switch (headerID) {
- case COUNT:
- if (!(headerValue instanceof Long)) {
- if (headerValue == null) {
- mCount = null;
- break;
- }
- throw new IllegalArgumentException("Count must be a Long");
- }
- temp = ((Long)headerValue).longValue();
- if ((temp < 0L) || (temp > 0xFFFFFFFFL)) {
- throw new IllegalArgumentException("Count must be between 0 and 0xFFFFFFFF");
- }
- mCount = (Long)headerValue;
- break;
- case NAME:
- if ((headerValue != null) && (!(headerValue instanceof String))) {
- throw new IllegalArgumentException("Name must be a String");
- }
- mEmptyName = false;
- mName = (String)headerValue;
- break;
- case TYPE:
- if ((headerValue != null) && (!(headerValue instanceof String))) {
- throw new IllegalArgumentException("Type must be a String");
- }
- mType = (String)headerValue;
- break;
- case LENGTH:
- if (!(headerValue instanceof Long)) {
- if (headerValue == null) {
- mLength = null;
- break;
- }
- throw new IllegalArgumentException("Length must be a Long");
- }
- temp = ((Long)headerValue).longValue();
- if ((temp < 0L) || (temp > 0xFFFFFFFFL)) {
- throw new IllegalArgumentException("Length must be between 0 and 0xFFFFFFFF");
- }
- mLength = (Long)headerValue;
- break;
- case TIME_ISO_8601:
- if ((headerValue != null) && (!(headerValue instanceof Calendar))) {
- throw new IllegalArgumentException("Time ISO 8601 must be a Calendar");
- }
- mIsoTime = (Calendar)headerValue;
- break;
- case TIME_4_BYTE:
- if ((headerValue != null) && (!(headerValue instanceof Calendar))) {
- throw new IllegalArgumentException("Time 4 Byte must be a Calendar");
- }
- mByteTime = (Calendar)headerValue;
- break;
- case DESCRIPTION:
- if ((headerValue != null) && (!(headerValue instanceof String))) {
- throw new IllegalArgumentException("Description must be a String");
- }
- mDescription = (String)headerValue;
- break;
- case TARGET:
- if (headerValue == null) {
- mTarget = null;
- } else {
- if (!(headerValue instanceof byte[])) {
- throw new IllegalArgumentException("Target must be a byte array");
- } else {
- mTarget = new byte[((byte[])headerValue).length];
- System.arraycopy(headerValue, 0, mTarget, 0, mTarget.length);
- }
- }
- break;
- case HTTP:
- if (headerValue == null) {
- mHttpHeader = null;
- } else {
- if (!(headerValue instanceof byte[])) {
- throw new IllegalArgumentException("HTTP must be a byte array");
- } else {
- mHttpHeader = new byte[((byte[])headerValue).length];
- System.arraycopy(headerValue, 0, mHttpHeader, 0, mHttpHeader.length);
- }
- }
- break;
- case WHO:
- if (headerValue == null) {
- mWho = null;
- } else {
- if (!(headerValue instanceof byte[])) {
- throw new IllegalArgumentException("WHO must be a byte array");
- } else {
- mWho = new byte[((byte[])headerValue).length];
- System.arraycopy(headerValue, 0, mWho, 0, mWho.length);
- }
- }
- break;
- case OBJECT_CLASS:
- if (headerValue == null) {
- mObjectClass = null;
- } else {
- if (!(headerValue instanceof byte[])) {
- throw new IllegalArgumentException("Object Class must be a byte array");
- } else {
- mObjectClass = new byte[((byte[])headerValue).length];
- System.arraycopy(headerValue, 0, mObjectClass, 0, mObjectClass.length);
- }
- }
- break;
- case APPLICATION_PARAMETER:
- if (headerValue == null) {
- mAppParam = null;
- } else {
- if (!(headerValue instanceof byte[])) {
- throw new IllegalArgumentException(
- "Application Parameter must be a byte array");
- } else {
- mAppParam = new byte[((byte[])headerValue).length];
- System.arraycopy(headerValue, 0, mAppParam, 0, mAppParam.length);
- }
- }
- break;
- case SINGLE_RESPONSE_MODE:
- if (headerValue == null) {
- mSingleResponseMode = null;
- } else {
- if (!(headerValue instanceof Byte)) {
- throw new IllegalArgumentException(
- "Single Response Mode must be a Byte");
- } else {
- mSingleResponseMode = (Byte)headerValue;
- }
- }
- break;
- case SINGLE_RESPONSE_MODE_PARAMETER:
- if (headerValue == null) {
- mSrmParam = null;
- } else {
- if (!(headerValue instanceof Byte)) {
- throw new IllegalArgumentException(
- "Single Response Mode Parameter must be a Byte");
- } else {
- mSrmParam = (Byte)headerValue;
- }
- }
- break;
- default:
- // Verify that it was not a Unicode String user Defined
- if ((headerID >= 0x30) && (headerID <= 0x3F)) {
- if ((headerValue != null) && (!(headerValue instanceof String))) {
- throw new IllegalArgumentException(
- "Unicode String User Defined must be a String");
- }
- mUnicodeUserDefined[headerID - 0x30] = (String)headerValue;
-
- break;
- }
- // Verify that it was not a byte sequence user defined value
- if ((headerID >= 0x70) && (headerID <= 0x7F)) {
-
- if (headerValue == null) {
- mSequenceUserDefined[headerID - 0x70] = null;
- } else {
- if (!(headerValue instanceof byte[])) {
- throw new IllegalArgumentException(
- "Byte Sequence User Defined must be a byte array");
- } else {
- mSequenceUserDefined[headerID - 0x70] = new byte[((byte[])headerValue).length];
- System.arraycopy(headerValue, 0, mSequenceUserDefined[headerID - 0x70],
- 0, mSequenceUserDefined[headerID - 0x70].length);
- }
- }
- break;
- }
- // Verify that it was not a Byte user Defined
- if ((headerID >= 0xB0) && (headerID <= 0xBF)) {
- if ((headerValue != null) && (!(headerValue instanceof Byte))) {
- throw new IllegalArgumentException("ByteUser Defined must be a Byte");
- }
- mByteUserDefined[headerID - 0xB0] = (Byte)headerValue;
-
- break;
- }
- // Verify that is was not the 4 byte unsigned integer user
- // defined header
- if ((headerID >= 0xF0) && (headerID <= 0xFF)) {
- if (!(headerValue instanceof Long)) {
- if (headerValue == null) {
- mIntegerUserDefined[headerID - 0xF0] = null;
- break;
- }
- throw new IllegalArgumentException("Integer User Defined must be a Long");
- }
- temp = ((Long)headerValue).longValue();
- if ((temp < 0L) || (temp > 0xFFFFFFFFL)) {
- throw new IllegalArgumentException(
- "Integer User Defined must be between 0 and 0xFFFFFFFF");
- }
- mIntegerUserDefined[headerID - 0xF0] = (Long)headerValue;
- break;
- }
- throw new IllegalArgumentException("Invalid Header Identifier");
- }
- }
-
- /**
- * Retrieves the value of the header identifier provided. The type of the
- * Object returned is defined in the description of this interface.
- * @param headerID the header identifier whose value is to be returned
- * @return the value of the header provided or <code>null</code> if the
- * header identifier specified is not part of this
- * <code>HeaderSet</code> object
- * @throws IllegalArgumentException if the <code>headerID</code> is not one
- * defined in this interface or any of the user-defined headers
- * @throws IOException if an error occurred in the transport layer during
- * the operation or if the connection has been closed
- */
- public Object getHeader(int headerID) throws IOException {
-
- switch (headerID) {
- case COUNT:
- return mCount;
- case NAME:
- return mName;
- case TYPE:
- return mType;
- case LENGTH:
- return mLength;
- case TIME_ISO_8601:
- return mIsoTime;
- case TIME_4_BYTE:
- return mByteTime;
- case DESCRIPTION:
- return mDescription;
- case TARGET:
- return mTarget;
- case HTTP:
- return mHttpHeader;
- case WHO:
- return mWho;
- case CONNECTION_ID:
- return mConnectionID;
- case OBJECT_CLASS:
- return mObjectClass;
- case APPLICATION_PARAMETER:
- return mAppParam;
- case SINGLE_RESPONSE_MODE:
- return mSingleResponseMode;
- case SINGLE_RESPONSE_MODE_PARAMETER:
- return mSrmParam;
- default:
- // Verify that it was not a Unicode String user Defined
- if ((headerID >= 0x30) && (headerID <= 0x3F)) {
- return mUnicodeUserDefined[headerID - 0x30];
- }
- // Verify that it was not a byte sequence user defined header
- if ((headerID >= 0x70) && (headerID <= 0x7F)) {
- return mSequenceUserDefined[headerID - 0x70];
- }
- // Verify that it was not a byte user defined header
- if ((headerID >= 0xB0) && (headerID <= 0xBF)) {
- return mByteUserDefined[headerID - 0xB0];
- }
- // Verify that it was not a integer user defined header
- if ((headerID >= 0xF0) && (headerID <= 0xFF)) {
- return mIntegerUserDefined[headerID - 0xF0];
- }
- throw new IllegalArgumentException("Invalid Header Identifier");
- }
- }
-
- /**
- * Retrieves the list of headers that may be retrieved via the
- * <code>getHeader</code> method that will not return <code>null</code>. In
- * other words, this method returns all the headers that are available in
- * this object.
- * @see #getHeader
- * @return the array of headers that are set in this object or
- * <code>null</code> if no headers are available
- * @throws IOException if an error occurred in the transport layer during
- * the operation or the connection has been closed
- */
- public int[] getHeaderList() throws IOException {
- ByteArrayOutputStream out = new ByteArrayOutputStream();
-
- if (mCount != null) {
- out.write(COUNT);
- }
- if (mName != null) {
- out.write(NAME);
- }
- if (mType != null) {
- out.write(TYPE);
- }
- if (mLength != null) {
- out.write(LENGTH);
- }
- if (mIsoTime != null) {
- out.write(TIME_ISO_8601);
- }
- if (mByteTime != null) {
- out.write(TIME_4_BYTE);
- }
- if (mDescription != null) {
- out.write(DESCRIPTION);
- }
- if (mTarget != null) {
- out.write(TARGET);
- }
- if (mHttpHeader != null) {
- out.write(HTTP);
- }
- if (mWho != null) {
- out.write(WHO);
- }
- if (mAppParam != null) {
- out.write(APPLICATION_PARAMETER);
- }
- if (mObjectClass != null) {
- out.write(OBJECT_CLASS);
- }
- if(mSingleResponseMode != null) {
- out.write(SINGLE_RESPONSE_MODE);
- }
- if(mSrmParam != null) {
- out.write(SINGLE_RESPONSE_MODE_PARAMETER);
- }
-
- for (int i = 0x30; i < 0x40; i++) {
- if (mUnicodeUserDefined[i - 0x30] != null) {
- out.write(i);
- }
- }
-
- for (int i = 0x70; i < 0x80; i++) {
- if (mSequenceUserDefined[i - 0x70] != null) {
- out.write(i);
- }
- }
-
- for (int i = 0xB0; i < 0xC0; i++) {
- if (mByteUserDefined[i - 0xB0] != null) {
- out.write(i);
- }
- }
-
- for (int i = 0xF0; i < 0x100; i++) {
- if (mIntegerUserDefined[i - 0xF0] != null) {
- out.write(i);
- }
- }
-
- byte[] headers = out.toByteArray();
- out.close();
-
- if ((headers == null) || (headers.length == 0)) {
- return null;
- }
-
- int[] result = new int[headers.length];
- for (int i = 0; i < headers.length; i++) {
- // Convert the byte to a positive integer. That is, an integer
- // between 0 and 256.
- result[i] = headers[i] & 0xFF;
- }
-
- return result;
- }
-
- /**
- * Sets the authentication challenge header. The <code>realm</code> will be
- * encoded based upon the default encoding scheme used by the implementation
- * to encode strings. Therefore, the encoding scheme used to encode the
- * <code>realm</code> is application dependent.
- * @param realm a short description that describes what password to use; if
- * <code>null</code> no realm will be sent in the authentication
- * challenge header
- * @param userID if <code>true</code>, a user ID is required in the reply;
- * if <code>false</code>, no user ID is required
- * @param access if <code>true</code> then full access will be granted if
- * successful; if <code>false</code> then read-only access will be
- * granted if successful
- * @throws IOException
- */
- public void createAuthenticationChallenge(String realm, boolean userID, boolean access)
- throws IOException {
-
- nonce = new byte[16];
- if(mRandom == null) {
- mRandom = new SecureRandom();
- }
- for (int i = 0; i < 16; i++) {
- nonce[i] = (byte)mRandom.nextInt();
- }
-
- mAuthChall = ObexHelper.computeAuthenticationChallenge(nonce, realm, access, userID);
- }
-
- /**
- * Returns the response code received from the server. Response codes are
- * defined in the <code>ResponseCodes</code> class.
- * @see ResponseCodes
- * @return the response code retrieved from the server
- * @throws IOException if an error occurred in the transport layer during
- * the transaction; if this method is called on a
- * <code>HeaderSet</code> object created by calling
- * <code>createHeaderSet()</code> in a <code>ClientSession</code>
- * object; if this object was created by an OBEX server
- */
- public int getResponseCode() throws IOException {
- if (responseCode == -1) {
- throw new IOException("May not be called on a server");
- } else {
- return responseCode;
- }
- }
-}
diff --git a/obex/javax/obex/ObexHelper.java b/obex/javax/obex/ObexHelper.java
deleted file mode 100644
index 843793a..0000000
--- a/obex/javax/obex/ObexHelper.java
+++ /dev/null
@@ -1,1100 +0,0 @@
-/*
- * Copyright (C) 2015 The Android Open Source Project
- * Copyright (C) 2015 Samsung LSI
- * Copyright (c) 2008-2009, Motorola, Inc.
- *
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of the Motorola, Inc. nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-package javax.obex;
-
-import android.util.Log;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.TimeZone;
-
-
-/**
- * This class defines a set of helper methods for the implementation of Obex.
- * @hide
- */
-public final class ObexHelper {
-
- private static final String TAG = "ObexHelper";
- public static final boolean VDBG = false;
- /**
- * Defines the basic packet length used by OBEX. Every OBEX packet has the
- * same basic format:<BR>
- * Byte 0: Request or Response Code Byte 1&2: Length of the packet.
- */
- public static final int BASE_PACKET_LENGTH = 3;
-
- /** Prevent object construction of helper class */
- private ObexHelper() {
- }
-
- /**
- * The maximum packet size for OBEX packets that this client can handle. At
- * present, this must be changed for each port. TODO: The max packet size
- * should be the Max incoming MTU minus TODO: L2CAP package headers and
- * RFCOMM package headers. TODO: Retrieve the max incoming MTU from TODO:
- * LocalDevice.getProperty().
- * NOTE: This value must be larger than or equal to the L2CAP SDU
- */
- /*
- * android note set as 0xFFFE to match remote MPS
- */
- public static final int MAX_PACKET_SIZE_INT = 0xFFFE;
-
- // The minimum allowed max packet size is 255 according to the OBEX specification
- public static final int LOWER_LIMIT_MAX_PACKET_SIZE = 255;
-
- // The length of OBEX Byte Sequency Header Id according to the OBEX specification
- public static final int OBEX_BYTE_SEQ_HEADER_LEN = 0x03;
-
- /**
- * Temporary workaround to be able to push files to Windows 7.
- * TODO: Should be removed as soon as Microsoft updates their driver.
- */
- public static final int MAX_CLIENT_PACKET_SIZE = 0xFC00;
-
- public static final int OBEX_OPCODE_FINAL_BIT_MASK = 0x80;
-
- public static final int OBEX_OPCODE_CONNECT = 0x80;
-
- public static final int OBEX_OPCODE_DISCONNECT = 0x81;
-
- public static final int OBEX_OPCODE_PUT = 0x02;
-
- public static final int OBEX_OPCODE_PUT_FINAL = 0x82;
-
- public static final int OBEX_OPCODE_GET = 0x03;
-
- public static final int OBEX_OPCODE_GET_FINAL = 0x83;
-
- public static final int OBEX_OPCODE_RESERVED = 0x04;
-
- public static final int OBEX_OPCODE_RESERVED_FINAL = 0x84;
-
- public static final int OBEX_OPCODE_SETPATH = 0x85;
-
- public static final int OBEX_OPCODE_ABORT = 0xFF;
-
- public static final int OBEX_AUTH_REALM_CHARSET_ASCII = 0x00;
-
- public static final int OBEX_AUTH_REALM_CHARSET_ISO_8859_1 = 0x01;
-
- public static final int OBEX_AUTH_REALM_CHARSET_ISO_8859_2 = 0x02;
-
- public static final int OBEX_AUTH_REALM_CHARSET_ISO_8859_3 = 0x03;
-
- public static final int OBEX_AUTH_REALM_CHARSET_ISO_8859_4 = 0x04;
-
- public static final int OBEX_AUTH_REALM_CHARSET_ISO_8859_5 = 0x05;
-
- public static final int OBEX_AUTH_REALM_CHARSET_ISO_8859_6 = 0x06;
-
- public static final int OBEX_AUTH_REALM_CHARSET_ISO_8859_7 = 0x07;
-
- public static final int OBEX_AUTH_REALM_CHARSET_ISO_8859_8 = 0x08;
-
- public static final int OBEX_AUTH_REALM_CHARSET_ISO_8859_9 = 0x09;
-
- public static final int OBEX_AUTH_REALM_CHARSET_UNICODE = 0xFF;
-
- public static final byte OBEX_SRM_ENABLE = 0x01; // For BT we only need enable/disable
- public static final byte OBEX_SRM_DISABLE = 0x00;
- public static final byte OBEX_SRM_SUPPORT = 0x02; // Unused for now
-
- public static final byte OBEX_SRMP_WAIT = 0x01; // Only SRMP value used by BT
-
- /**
- * Updates the HeaderSet with the headers received in the byte array
- * provided. Invalid headers are ignored.
- * <P>
- * The first two bits of an OBEX Header specifies the type of object that is
- * being sent. The table below specifies the meaning of the high bits.
- * <TABLE>
- * <TR>
- * <TH>Bits 8 and 7</TH>
- * <TH>Value</TH>
- * <TH>Description</TH>
- * </TR>
- * <TR>
- * <TD>00</TD>
- * <TD>0x00</TD>
- * <TD>Null Terminated Unicode text, prefixed with 2 byte unsigned integer</TD>
- * </TR>
- * <TR>
- * <TD>01</TD>
- * <TD>0x40</TD>
- * <TD>Byte Sequence, length prefixed with 2 byte unsigned integer</TD>
- * </TR>
- * <TR>
- * <TD>10</TD>
- * <TD>0x80</TD>
- * <TD>1 byte quantity</TD>
- * </TR>
- * <TR>
- * <TD>11</TD>
- * <TD>0xC0</TD>
- * <TD>4 byte quantity - transmitted in network byte order (high byte first</TD>
- * </TR>
- * </TABLE>
- * This method uses the information in this table to determine the type of
- * Java object to create and passes that object with the full header to
- * setHeader() to update the HeaderSet object. Invalid headers will cause an
- * exception to be thrown. When it is thrown, it is ignored.
- * @param header the HeaderSet to update
- * @param headerArray the byte array containing headers
- * @return the result of the last start body or end body header provided;
- * the first byte in the result will specify if a body or end of
- * body is received
- * @throws IOException if an invalid header was found
- */
- public static byte[] updateHeaderSet(HeaderSet header, byte[] headerArray) throws IOException {
- int index = 0;
- int length = 0;
- int headerID;
- byte[] value = null;
- byte[] body = null;
- HeaderSet headerImpl = header;
- try {
- while (index < headerArray.length) {
- headerID = 0xFF & headerArray[index];
- switch (headerID & (0xC0)) {
-
- /*
- * 0x00 is a unicode null terminate string with the first
- * two bytes after the header identifier being the length
- */
- case 0x00:
- // Fall through
- /*
- * 0x40 is a byte sequence with the first
- * two bytes after the header identifier being the length
- */
- case 0x40:
- boolean trimTail = true;
- index++;
- length = ((0xFF & headerArray[index]) << 8) +
- (0xFF & headerArray[index + 1]);
- index += 2;
- if (length <= OBEX_BYTE_SEQ_HEADER_LEN) {
- Log.e(TAG, "Remote sent an OBEX packet with " +
- "incorrect header length = " + length);
- break;
- }
- length -= OBEX_BYTE_SEQ_HEADER_LEN;
- value = new byte[length];
- System.arraycopy(headerArray, index, value, 0, length);
- if (length == 0 || (length > 0 && (value[length - 1] != 0))) {
- trimTail = false;
- }
- switch (headerID) {
- case HeaderSet.TYPE:
- try {
- // Remove trailing null
- if (trimTail == false) {
- headerImpl.setHeader(headerID, new String(value, 0,
- value.length, "ISO8859_1"));
- } else {
- headerImpl.setHeader(headerID, new String(value, 0,
- value.length - 1, "ISO8859_1"));
- }
- } catch (UnsupportedEncodingException e) {
- throw e;
- }
- break;
-
- case HeaderSet.AUTH_CHALLENGE:
- headerImpl.mAuthChall = new byte[length];
- System.arraycopy(headerArray, index, headerImpl.mAuthChall, 0,
- length);
- break;
-
- case HeaderSet.AUTH_RESPONSE:
- headerImpl.mAuthResp = new byte[length];
- System.arraycopy(headerArray, index, headerImpl.mAuthResp, 0,
- length);
- break;
-
- case HeaderSet.BODY:
- /* Fall Through */
- case HeaderSet.END_OF_BODY:
- body = new byte[length + 1];
- body[0] = (byte)headerID;
- System.arraycopy(headerArray, index, body, 1, length);
- break;
-
- case HeaderSet.TIME_ISO_8601:
- try {
- String dateString = new String(value, "ISO8859_1");
- Calendar temp = Calendar.getInstance();
- if ((dateString.length() == 16)
- && (dateString.charAt(15) == 'Z')) {
- temp.setTimeZone(TimeZone.getTimeZone("UTC"));
- }
- temp.set(Calendar.YEAR, Integer.parseInt(dateString.substring(
- 0, 4)));
- temp.set(Calendar.MONTH, Integer.parseInt(dateString.substring(
- 4, 6)));
- temp.set(Calendar.DAY_OF_MONTH, Integer.parseInt(dateString
- .substring(6, 8)));
- temp.set(Calendar.HOUR_OF_DAY, Integer.parseInt(dateString
- .substring(9, 11)));
- temp.set(Calendar.MINUTE, Integer.parseInt(dateString
- .substring(11, 13)));
- temp.set(Calendar.SECOND, Integer.parseInt(dateString
- .substring(13, 15)));
- headerImpl.setHeader(HeaderSet.TIME_ISO_8601, temp);
- } catch (UnsupportedEncodingException e) {
- throw e;
- }
- break;
-
- default:
- if ((headerID & 0xC0) == 0x00) {
- headerImpl.setHeader(headerID, ObexHelper.convertToUnicode(
- value, true));
- } else {
- headerImpl.setHeader(headerID, value);
- }
- }
-
- index += length;
- break;
-
- /*
- * 0x80 is a byte header. The only valid byte headers are
- * the 16 user defined byte headers.
- */
- case 0x80:
- index++;
- try {
- headerImpl.setHeader(headerID, Byte.valueOf(headerArray[index]));
- } catch (Exception e) {
- // Not a valid header so ignore
- }
- index++;
- break;
-
- /*
- * 0xC0 is a 4 byte unsigned integer header and with the
- * exception of TIME_4_BYTE will be converted to a Long
- * and added.
- */
- case 0xC0:
- index++;
- value = new byte[4];
- System.arraycopy(headerArray, index, value, 0, 4);
- try {
- if (headerID != HeaderSet.TIME_4_BYTE) {
- // Determine if it is a connection ID. These
- // need to be handled differently
- if (headerID == HeaderSet.CONNECTION_ID) {
- headerImpl.mConnectionID = new byte[4];
- System.arraycopy(value, 0, headerImpl.mConnectionID, 0, 4);
- } else {
- headerImpl.setHeader(headerID, Long
- .valueOf(convertToLong(value)));
- }
- } else {
- Calendar temp = Calendar.getInstance();
- temp.setTime(new Date(convertToLong(value) * 1000L));
- headerImpl.setHeader(HeaderSet.TIME_4_BYTE, temp);
- }
- } catch (Exception e) {
- // Not a valid header so ignore
- throw new IOException("Header was not formatted properly", e);
- }
- index += 4;
- break;
- }
-
- }
- } catch (IOException e) {
- throw new IOException("Header was not formatted properly", e);
- }
-
- return body;
- }
-
- /**
- * Creates the header part of OBEX packet based on the header provided.
- * TODO: Could use getHeaderList() to get the array of headers to include
- * and then use the high two bits to determine the the type of the object
- * and construct the byte array from that. This will make the size smaller.
- * @param head the header used to construct the byte array
- * @param nullOut <code>true</code> if the header should be set to
- * <code>null</code> once it is added to the array or
- * <code>false</code> if it should not be nulled out
- * @return the header of an OBEX packet
- */
- public static byte[] createHeader(HeaderSet head, boolean nullOut) {
- Long intHeader = null;
- String stringHeader = null;
- Calendar dateHeader = null;
- Byte byteHeader = null;
- StringBuffer buffer = null;
- byte[] value = null;
- byte[] result = null;
- byte[] lengthArray = new byte[2];
- int length;
- HeaderSet headImpl = null;
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- headImpl = head;
-
- try {
- /*
- * Determine if there is a connection ID to send. If there is,
- * then it should be the first header in the packet.
- */
- if ((headImpl.mConnectionID != null) && (headImpl.getHeader(HeaderSet.TARGET) == null)) {
-
- out.write((byte)HeaderSet.CONNECTION_ID);
- out.write(headImpl.mConnectionID);
- }
-
- // Count Header
- intHeader = (Long)headImpl.getHeader(HeaderSet.COUNT);
- if (intHeader != null) {
- out.write((byte)HeaderSet.COUNT);
- value = ObexHelper.convertToByteArray(intHeader.longValue());
- out.write(value);
- if (nullOut) {
- headImpl.setHeader(HeaderSet.COUNT, null);
- }
- }
-
- // Name Header
- stringHeader = (String)headImpl.getHeader(HeaderSet.NAME);
- if (stringHeader != null) {
- out.write((byte)HeaderSet.NAME);
- value = ObexHelper.convertToUnicodeByteArray(stringHeader);
- length = value.length + 3;
- lengthArray[0] = (byte)(0xFF & (length >> 8));
- lengthArray[1] = (byte)(0xFF & length);
- out.write(lengthArray);
- out.write(value);
- if (nullOut) {
- headImpl.setHeader(HeaderSet.NAME, null);
- }
- } else if (headImpl.getEmptyNameHeader()) {
- out.write((byte) HeaderSet.NAME);
- lengthArray[0] = (byte) 0x00;
- lengthArray[1] = (byte) 0x03;
- out.write(lengthArray);
- }
-
- // Type Header
- stringHeader = (String)headImpl.getHeader(HeaderSet.TYPE);
- if (stringHeader != null) {
- out.write((byte)HeaderSet.TYPE);
- try {
- value = stringHeader.getBytes("ISO8859_1");
- } catch (UnsupportedEncodingException e) {
- throw e;
- }
-
- length = value.length + 4;
- lengthArray[0] = (byte)(255 & (length >> 8));
- lengthArray[1] = (byte)(255 & length);
- out.write(lengthArray);
- out.write(value);
- out.write(0x00);
- if (nullOut) {
- headImpl.setHeader(HeaderSet.TYPE, null);
- }
- }
-
- // Length Header
- intHeader = (Long)headImpl.getHeader(HeaderSet.LENGTH);
- if (intHeader != null) {
- out.write((byte)HeaderSet.LENGTH);
- value = ObexHelper.convertToByteArray(intHeader.longValue());
- out.write(value);
- if (nullOut) {
- headImpl.setHeader(HeaderSet.LENGTH, null);
- }
- }
-
- // Time ISO Header
- dateHeader = (Calendar)headImpl.getHeader(HeaderSet.TIME_ISO_8601);
- if (dateHeader != null) {
-
- /*
- * The ISO Header should take the form YYYYMMDDTHHMMSSZ. The
- * 'Z' will only be included if it is a UTC time.
- */
- buffer = new StringBuffer();
- int temp = dateHeader.get(Calendar.YEAR);
- for (int i = temp; i < 1000; i = i * 10) {
- buffer.append("0");
- }
- buffer.append(temp);
- temp = dateHeader.get(Calendar.MONTH);
- if (temp < 10) {
- buffer.append("0");
- }
- buffer.append(temp);
- temp = dateHeader.get(Calendar.DAY_OF_MONTH);
- if (temp < 10) {
- buffer.append("0");
- }
- buffer.append(temp);
- buffer.append("T");
- temp = dateHeader.get(Calendar.HOUR_OF_DAY);
- if (temp < 10) {
- buffer.append("0");
- }
- buffer.append(temp);
- temp = dateHeader.get(Calendar.MINUTE);
- if (temp < 10) {
- buffer.append("0");
- }
- buffer.append(temp);
- temp = dateHeader.get(Calendar.SECOND);
- if (temp < 10) {
- buffer.append("0");
- }
- buffer.append(temp);
-
- if (dateHeader.getTimeZone().getID().equals("UTC")) {
- buffer.append("Z");
- }
-
- try {
- value = buffer.toString().getBytes("ISO8859_1");
- } catch (UnsupportedEncodingException e) {
- throw e;
- }
-
- length = value.length + 3;
- lengthArray[0] = (byte)(255 & (length >> 8));
- lengthArray[1] = (byte)(255 & length);
- out.write(HeaderSet.TIME_ISO_8601);
- out.write(lengthArray);
- out.write(value);
- if (nullOut) {
- headImpl.setHeader(HeaderSet.TIME_ISO_8601, null);
- }
- }
-
- // Time 4 Byte Header
- dateHeader = (Calendar)headImpl.getHeader(HeaderSet.TIME_4_BYTE);
- if (dateHeader != null) {
- out.write(HeaderSet.TIME_4_BYTE);
-
- /*
- * Need to call getTime() twice. The first call will return
- * a java.util.Date object. The second call returns the number
- * of milliseconds since January 1, 1970. We need to convert
- * it to seconds since the TIME_4_BYTE expects the number of
- * seconds since January 1, 1970.
- */
- value = ObexHelper.convertToByteArray(dateHeader.getTime().getTime() / 1000L);
- out.write(value);
- if (nullOut) {
- headImpl.setHeader(HeaderSet.TIME_4_BYTE, null);
- }
- }
-
- // Description Header
- stringHeader = (String)headImpl.getHeader(HeaderSet.DESCRIPTION);
- if (stringHeader != null) {
- out.write((byte)HeaderSet.DESCRIPTION);
- value = ObexHelper.convertToUnicodeByteArray(stringHeader);
- length = value.length + 3;
- lengthArray[0] = (byte)(255 & (length >> 8));
- lengthArray[1] = (byte)(255 & length);
- out.write(lengthArray);
- out.write(value);
- if (nullOut) {
- headImpl.setHeader(HeaderSet.DESCRIPTION, null);
- }
- }
-
- // Target Header
- value = (byte[])headImpl.getHeader(HeaderSet.TARGET);
- if (value != null) {
- out.write((byte)HeaderSet.TARGET);
- length = value.length + 3;
- lengthArray[0] = (byte)(255 & (length >> 8));
- lengthArray[1] = (byte)(255 & length);
- out.write(lengthArray);
- out.write(value);
- if (nullOut) {
- headImpl.setHeader(HeaderSet.TARGET, null);
- }
- }
-
- // HTTP Header
- value = (byte[])headImpl.getHeader(HeaderSet.HTTP);
- if (value != null) {
- out.write((byte)HeaderSet.HTTP);
- length = value.length + 3;
- lengthArray[0] = (byte)(255 & (length >> 8));
- lengthArray[1] = (byte)(255 & length);
- out.write(lengthArray);
- out.write(value);
- if (nullOut) {
- headImpl.setHeader(HeaderSet.HTTP, null);
- }
- }
-
- // Who Header
- value = (byte[])headImpl.getHeader(HeaderSet.WHO);
- if (value != null) {
- out.write((byte)HeaderSet.WHO);
- length = value.length + 3;
- lengthArray[0] = (byte)(255 & (length >> 8));
- lengthArray[1] = (byte)(255 & length);
- out.write(lengthArray);
- out.write(value);
- if (nullOut) {
- headImpl.setHeader(HeaderSet.WHO, null);
- }
- }
-
- // Connection ID Header
- value = (byte[])headImpl.getHeader(HeaderSet.APPLICATION_PARAMETER);
- if (value != null) {
- out.write((byte)HeaderSet.APPLICATION_PARAMETER);
- length = value.length + 3;
- lengthArray[0] = (byte)(255 & (length >> 8));
- lengthArray[1] = (byte)(255 & length);
- out.write(lengthArray);
- out.write(value);
- if (nullOut) {
- headImpl.setHeader(HeaderSet.APPLICATION_PARAMETER, null);
- }
- }
-
- // Object Class Header
- value = (byte[])headImpl.getHeader(HeaderSet.OBJECT_CLASS);
- if (value != null) {
- out.write((byte)HeaderSet.OBJECT_CLASS);
- length = value.length + 3;
- lengthArray[0] = (byte)(255 & (length >> 8));
- lengthArray[1] = (byte)(255 & length);
- out.write(lengthArray);
- out.write(value);
- if (nullOut) {
- headImpl.setHeader(HeaderSet.OBJECT_CLASS, null);
- }
- }
-
- // Check User Defined Headers
- for (int i = 0; i < 16; i++) {
-
- //Unicode String Header
- stringHeader = (String)headImpl.getHeader(i + 0x30);
- if (stringHeader != null) {
- out.write((byte)i + 0x30);
- value = ObexHelper.convertToUnicodeByteArray(stringHeader);
- length = value.length + 3;
- lengthArray[0] = (byte)(255 & (length >> 8));
- lengthArray[1] = (byte)(255 & length);
- out.write(lengthArray);
- out.write(value);
- if (nullOut) {
- headImpl.setHeader(i + 0x30, null);
- }
- }
-
- // Byte Sequence Header
- value = (byte[])headImpl.getHeader(i + 0x70);
- if (value != null) {
- out.write((byte)i + 0x70);
- length = value.length + 3;
- lengthArray[0] = (byte)(255 & (length >> 8));
- lengthArray[1] = (byte)(255 & length);
- out.write(lengthArray);
- out.write(value);
- if (nullOut) {
- headImpl.setHeader(i + 0x70, null);
- }
- }
-
- // Byte Header
- byteHeader = (Byte)headImpl.getHeader(i + 0xB0);
- if (byteHeader != null) {
- out.write((byte)i + 0xB0);
- out.write(byteHeader.byteValue());
- if (nullOut) {
- headImpl.setHeader(i + 0xB0, null);
- }
- }
-
- // Integer header
- intHeader = (Long)headImpl.getHeader(i + 0xF0);
- if (intHeader != null) {
- out.write((byte)i + 0xF0);
- out.write(ObexHelper.convertToByteArray(intHeader.longValue()));
- if (nullOut) {
- headImpl.setHeader(i + 0xF0, null);
- }
- }
- }
-
- // Add the authentication challenge header
- if (headImpl.mAuthChall != null) {
- out.write((byte)HeaderSet.AUTH_CHALLENGE);
- length = headImpl.mAuthChall.length + 3;
- lengthArray[0] = (byte)(255 & (length >> 8));
- lengthArray[1] = (byte)(255 & length);
- out.write(lengthArray);
- out.write(headImpl.mAuthChall);
- if (nullOut) {
- headImpl.mAuthChall = null;
- }
- }
-
- // Add the authentication response header
- if (headImpl.mAuthResp != null) {
- out.write((byte)HeaderSet.AUTH_RESPONSE);
- length = headImpl.mAuthResp.length + 3;
- lengthArray[0] = (byte)(255 & (length >> 8));
- lengthArray[1] = (byte)(255 & length);
- out.write(lengthArray);
- out.write(headImpl.mAuthResp);
- if (nullOut) {
- headImpl.mAuthResp = null;
- }
- }
-
- // TODO:
- // If the SRM and SRMP header is in use, they must be send in the same OBEX packet
- // But the current structure of the obex code cannot handle this, and therefore
- // it makes sense to put them in the tail of the headers, since we then reduce the
- // chance of enabling SRM to soon. The down side is that SRM cannot be used while
- // transferring non-body headers
-
- // Add the SRM header
- byteHeader = (Byte)headImpl.getHeader(HeaderSet.SINGLE_RESPONSE_MODE);
- if (byteHeader != null) {
- out.write((byte)HeaderSet.SINGLE_RESPONSE_MODE);
- out.write(byteHeader.byteValue());
- if (nullOut) {
- headImpl.setHeader(HeaderSet.SINGLE_RESPONSE_MODE, null);
- }
- }
-
- // Add the SRM parameter header
- byteHeader = (Byte)headImpl.getHeader(HeaderSet.SINGLE_RESPONSE_MODE_PARAMETER);
- if (byteHeader != null) {
- out.write((byte)HeaderSet.SINGLE_RESPONSE_MODE_PARAMETER);
- out.write(byteHeader.byteValue());
- if (nullOut) {
- headImpl.setHeader(HeaderSet.SINGLE_RESPONSE_MODE_PARAMETER, null);
- }
- }
-
- } catch (IOException e) {
- } finally {
- result = out.toByteArray();
- try {
- out.close();
- } catch (Exception ex) {
- }
- }
-
- return result;
-
- }
-
- /**
- * Determines where the maximum divide is between headers. This method is
- * used by put and get operations to separate headers to a size that meets
- * the max packet size allowed.
- * @param headerArray the headers to separate
- * @param start the starting index to search
- * @param maxSize the maximum size of a packet
- * @return the index of the end of the header block to send or -1 if the
- * header could not be divided because the header is too large
- */
- public static int findHeaderEnd(byte[] headerArray, int start, int maxSize) {
-
- int fullLength = 0;
- int lastLength = -1;
- int index = start;
- int length = 0;
-
- // TODO: Ensure SRM and SRMP headers are not split into two OBEX packets
-
- while ((fullLength < maxSize) && (index < headerArray.length)) {
- int headerID = (headerArray[index] < 0 ? headerArray[index] + 256 : headerArray[index]);
- lastLength = fullLength;
-
- switch (headerID & (0xC0)) {
-
- case 0x00:
- // Fall through
- case 0x40:
-
- index++;
- length = (headerArray[index] < 0 ? headerArray[index] + 256
- : headerArray[index]);
- length = length << 8;
- index++;
- length += (headerArray[index] < 0 ? headerArray[index] + 256
- : headerArray[index]);
- length -= 3;
- index++;
- index += length;
- fullLength += length + 3;
- break;
-
- case 0x80:
-
- index++;
- index++;
- fullLength += 2;
- break;
-
- case 0xC0:
-
- index += 5;
- fullLength += 5;
- break;
-
- }
-
- }
-
- /*
- * Determine if this is the last header or not
- */
- if (lastLength == 0) {
- /*
- * Since this is the last header, check to see if the size of this
- * header is less then maxSize. If it is, return the length of the
- * header, otherwise return -1. The length of the header is
- * returned since it would be the start of the next header
- */
- if (fullLength < maxSize) {
- return headerArray.length;
- } else {
- return -1;
- }
- } else {
- return lastLength + start;
- }
- }
-
- /**
- * Converts the byte array to a long.
- * @param b the byte array to convert to a long
- * @return the byte array as a long
- */
- public static long convertToLong(byte[] b) {
- long result = 0;
- long value = 0;
- long power = 0;
-
- for (int i = (b.length - 1); i >= 0; i--) {
- value = b[i];
- if (value < 0) {
- value += 256;
- }
-
- result = result | (value << power);
- power += 8;
- }
-
- return result;
- }
-
- /**
- * Converts the long to a 4 byte array. The long must be non negative.
- * @param l the long to convert
- * @return a byte array that is the same as the long
- */
- public static byte[] convertToByteArray(long l) {
- byte[] b = new byte[4];
-
- b[0] = (byte)(255 & (l >> 24));
- b[1] = (byte)(255 & (l >> 16));
- b[2] = (byte)(255 & (l >> 8));
- b[3] = (byte)(255 & l);
-
- return b;
- }
-
- /**
- * Converts the String to a UNICODE byte array. It will also add the ending
- * null characters to the end of the string.
- * @param s the string to convert
- * @return the unicode byte array of the string
- */
- public static byte[] convertToUnicodeByteArray(String s) {
- if (s == null) {
- return null;
- }
-
- char c[] = s.toCharArray();
- byte[] result = new byte[(c.length * 2) + 2];
- for (int i = 0; i < c.length; i++) {
- result[(i * 2)] = (byte)(c[i] >> 8);
- result[((i * 2) + 1)] = (byte)c[i];
- }
-
- // Add the UNICODE null character
- result[result.length - 2] = 0;
- result[result.length - 1] = 0;
-
- return result;
- }
-
- /**
- * Retrieves the value from the byte array for the tag value specified. The
- * array should be of the form Tag - Length - Value triplet.
- * @param tag the tag to retrieve from the byte array
- * @param triplet the byte sequence containing the tag length value form
- * @return the value of the specified tag
- */
- public static byte[] getTagValue(byte tag, byte[] triplet) {
-
- int index = findTag(tag, triplet);
- if (index == -1) {
- return null;
- }
-
- index++;
- int length = triplet[index] & 0xFF;
-
- byte[] result = new byte[length];
- index++;
- System.arraycopy(triplet, index, result, 0, length);
-
- return result;
- }
-
- /**
- * Finds the index that starts the tag value pair in the byte array provide.
- * @param tag the tag to look for
- * @param value the byte array to search
- * @return the starting index of the tag or -1 if the tag could not be found
- */
- public static int findTag(byte tag, byte[] value) {
- int length = 0;
-
- if (value == null) {
- return -1;
- }
-
- int index = 0;
-
- while ((index < value.length) && (value[index] != tag)) {
- length = value[index + 1] & 0xFF;
- index += length + 2;
- }
-
- if (index >= value.length) {
- return -1;
- }
-
- return index;
- }
-
- /**
- * Converts the byte array provided to a unicode string.
- * @param b the byte array to convert to a string
- * @param includesNull determine if the byte string provided contains the
- * UNICODE null character at the end or not; if it does, it will be
- * removed
- * @return a Unicode string
- * @throws IllegalArgumentException if the byte array has an odd length
- */
- public static String convertToUnicode(byte[] b, boolean includesNull) {
- if (b == null || b.length == 0) {
- return null;
- }
- int arrayLength = b.length;
- if (!((arrayLength % 2) == 0)) {
- throw new IllegalArgumentException("Byte array not of a valid form");
- }
- arrayLength = (arrayLength >> 1);
- if (includesNull) {
- arrayLength -= 1;
- }
-
- char[] c = new char[arrayLength];
- for (int i = 0; i < arrayLength; i++) {
- int upper = b[2 * i];
- int lower = b[(2 * i) + 1];
- if (upper < 0) {
- upper += 256;
- }
- if (lower < 0) {
- lower += 256;
- }
- // If upper and lower both equal 0, it should be the end of string.
- // Ignore left bytes from array to avoid potential issues
- if (upper == 0 && lower == 0) {
- return new String(c, 0, i);
- }
-
- c[i] = (char)((upper << 8) | lower);
- }
-
- return new String(c);
- }
-
- /**
- * Compute the MD5 hash of the byte array provided. Does not accumulate
- * input.
- * @param in the byte array to hash
- * @return the MD5 hash of the byte array
- */
- public static byte[] computeMd5Hash(byte[] in) {
- try {
- MessageDigest md5 = MessageDigest.getInstance("MD5");
- return md5.digest(in);
- } catch (NoSuchAlgorithmException e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Computes an authentication challenge header.
- * @param nonce the challenge that will be provided to the peer; the
- * challenge must be 16 bytes long
- * @param realm a short description that describes what password to use
- * @param access if <code>true</code> then full access will be granted if
- * successful; if <code>false</code> then read only access will be
- * granted if successful
- * @param userID if <code>true</code>, a user ID is required in the reply;
- * if <code>false</code>, no user ID is required
- * @throws IllegalArgumentException if the challenge is not 16 bytes long;
- * if the realm can not be encoded in less then 255 bytes
- * @throws IOException if the encoding scheme ISO 8859-1 is not supported
- */
- public static byte[] computeAuthenticationChallenge(byte[] nonce, String realm, boolean access,
- boolean userID) throws IOException {
- byte[] authChall = null;
-
- if (nonce.length != 16) {
- throw new IllegalArgumentException("Nonce must be 16 bytes long");
- }
-
- /*
- * The authentication challenge is a byte sequence of the following form
- * byte 0: 0x00 - the tag for the challenge
- * byte 1: 0x10 - the length of the challenge; must be 16
- * byte 2-17: the authentication challenge
- * byte 18: 0x01 - the options tag; this is optional in the spec, but
- * we are going to include it in every message
- * byte 19: 0x01 - length of the options; must be 1
- * byte 20: the value of the options; bit 0 is set if user ID is
- * required; bit 1 is set if access mode is read only
- * byte 21: 0x02 - the tag for authentication realm; only included if
- * an authentication realm is specified
- * byte 22: the length of the authentication realm; only included if
- * the authentication realm is specified
- * byte 23: the encoding scheme of the authentication realm; we will use
- * the ISO 8859-1 encoding scheme since it is part of the KVM
- * byte 24 & up: the realm if one is specified.
- */
- if (realm == null) {
- authChall = new byte[21];
- } else {
- if (realm.length() >= 255) {
- throw new IllegalArgumentException("Realm must be less then 255 bytes");
- }
- authChall = new byte[24 + realm.length()];
- authChall[21] = 0x02;
- authChall[22] = (byte)(realm.length() + 1);
- authChall[23] = 0x01; // ISO 8859-1 Encoding
- System.arraycopy(realm.getBytes("ISO8859_1"), 0, authChall, 24, realm.length());
- }
-
- // Include the nonce field in the header
- authChall[0] = 0x00;
- authChall[1] = 0x10;
- System.arraycopy(nonce, 0, authChall, 2, 16);
-
- // Include the options header
- authChall[18] = 0x01;
- authChall[19] = 0x01;
- authChall[20] = 0x00;
-
- if (!access) {
- authChall[20] = (byte)(authChall[20] | 0x02);
- }
- if (userID) {
- authChall[20] = (byte)(authChall[20] | 0x01);
- }
-
- return authChall;
- }
-
- /**
- * Return the maximum allowed OBEX packet to transmit.
- * OBEX packets transmitted must be smaller than this value.
- * @param transport Reference to the ObexTransport in use.
- * @return the maximum allowed OBEX packet to transmit
- */
- public static int getMaxTxPacketSize(ObexTransport transport) {
- int size = transport.getMaxTransmitPacketSize();
- return validateMaxPacketSize(size);
- }
-
- /**
- * Return the maximum allowed OBEX packet to receive - used in OBEX connect.
- * @param transport
- * @return he maximum allowed OBEX packet to receive
- */
- public static int getMaxRxPacketSize(ObexTransport transport) {
- int size = transport.getMaxReceivePacketSize();
- return validateMaxPacketSize(size);
- }
-
- private static int validateMaxPacketSize(int size) {
- if (VDBG && (size > MAX_PACKET_SIZE_INT)) {
- Log.w(TAG, "The packet size supported for the connection (" + size + ") is larger"
- + " than the configured OBEX packet size: " + MAX_PACKET_SIZE_INT);
- }
- if (size != -1 && size < MAX_PACKET_SIZE_INT) {
- if (size < LOWER_LIMIT_MAX_PACKET_SIZE) {
- throw new IllegalArgumentException(size + " is less that the lower limit: "
- + LOWER_LIMIT_MAX_PACKET_SIZE);
- }
- return size;
- }
- return MAX_PACKET_SIZE_INT;
- }
-}
diff --git a/obex/javax/obex/ObexSession.java b/obex/javax/obex/ObexSession.java
deleted file mode 100644
index 542b9c8..0000000
--- a/obex/javax/obex/ObexSession.java
+++ /dev/null
@@ -1,224 +0,0 @@
-/*
- * Copyright (c) 2008-2009, Motorola, Inc.
- *
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of the Motorola, Inc. nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-package javax.obex;
-
-import java.io.IOException;
-
-import android.util.Log;
-
-/**
- * The <code>ObexSession</code> interface characterizes the term
- * "OBEX Connection" as defined in the IrDA Object Exchange Protocol v1.2, which
- * could be the server-side view of an OBEX connection, or the client-side view
- * of the same connection, which is established by server's accepting of a
- * client issued "CONNECT".
- * <P>
- * This interface serves as the common super class for
- * <CODE>ClientSession</CODE> and <CODE>ServerSession</CODE>.
- * @hide
- */
-public class ObexSession {
-
- private static final String TAG = "ObexSession";
- private static final boolean V = ObexHelper.VDBG;
-
- protected Authenticator mAuthenticator;
-
- protected byte[] mChallengeDigest;
-
- /**
- * Called when the server received an authentication challenge header. This
- * will cause the authenticator to handle the authentication challenge.
- * @param header the header with the authentication challenge
- * @return <code>true</code> if the last request should be resent;
- * <code>false</code> if the last request should not be resent
- * @throws IOException
- */
- public boolean handleAuthChall(HeaderSet header) throws IOException {
- if (mAuthenticator == null) {
- return false;
- }
-
- /*
- * An authentication challenge is made up of one required and two
- * optional tag length value triplets. The tag 0x00 is required to be in
- * the authentication challenge and it represents the challenge digest
- * that was received. The tag 0x01 is the options tag. This tag tracks
- * if user ID is required and if full access will be granted. The tag
- * 0x02 is the realm, which provides a description of which user name
- * and password to use.
- */
- byte[] challenge = ObexHelper.getTagValue((byte)0x00, header.mAuthChall);
- byte[] option = ObexHelper.getTagValue((byte)0x01, header.mAuthChall);
- byte[] description = ObexHelper.getTagValue((byte)0x02, header.mAuthChall);
-
- String realm = null;
- if (description != null) {
- byte[] realmString = new byte[description.length - 1];
- System.arraycopy(description, 1, realmString, 0, realmString.length);
-
- switch (description[0] & 0xFF) {
-
- case ObexHelper.OBEX_AUTH_REALM_CHARSET_ASCII:
- // ASCII encoding
- // Fall through
- case ObexHelper.OBEX_AUTH_REALM_CHARSET_ISO_8859_1:
- // ISO-8859-1 encoding
- try {
- realm = new String(realmString, "ISO8859_1");
- } catch (Exception e) {
- throw new IOException("Unsupported Encoding Scheme");
- }
- break;
-
- case ObexHelper.OBEX_AUTH_REALM_CHARSET_UNICODE:
- // UNICODE Encoding
- realm = ObexHelper.convertToUnicode(realmString, false);
- break;
-
- default:
- throw new IOException("Unsupported Encoding Scheme");
- }
- }
-
- boolean isUserIDRequired = false;
- boolean isFullAccess = true;
- if (option != null) {
- if ((option[0] & 0x01) != 0) {
- isUserIDRequired = true;
- }
-
- if ((option[0] & 0x02) != 0) {
- isFullAccess = false;
- }
- }
-
- PasswordAuthentication result = null;
- header.mAuthChall = null;
-
- try {
- result = mAuthenticator
- .onAuthenticationChallenge(realm, isUserIDRequired, isFullAccess);
- } catch (Exception e) {
- if (V) Log.d(TAG, "Exception occured - returning false", e);
- return false;
- }
-
- /*
- * If no password is provided then we not resent the request
- */
- if (result == null) {
- return false;
- }
-
- byte[] password = result.getPassword();
- if (password == null) {
- return false;
- }
-
- byte[] userName = result.getUserName();
-
- /*
- * Create the authentication response header. It includes 1 required and
- * 2 option tag length value triples. The required triple has a tag of
- * 0x00 and is the response digest. The first optional tag is 0x01 and
- * represents the user ID. If no user ID is provided, then no user ID
- * will be sent. The second optional tag is 0x02 and is the challenge
- * that was received. This will always be sent
- */
- if (userName != null) {
- header.mAuthResp = new byte[38 + userName.length];
- header.mAuthResp[36] = (byte)0x01;
- header.mAuthResp[37] = (byte)userName.length;
- System.arraycopy(userName, 0, header.mAuthResp, 38, userName.length);
- } else {
- header.mAuthResp = new byte[36];
- }
-
- // Create the secret String
- byte[] digest = new byte[challenge.length + password.length + 1];
- System.arraycopy(challenge, 0, digest, 0, challenge.length);
- // Insert colon between challenge and password
- digest[challenge.length] = (byte)0x3A;
- System.arraycopy(password, 0, digest, challenge.length + 1, password.length);
-
- // Add the Response Digest
- header.mAuthResp[0] = (byte)0x00;
- header.mAuthResp[1] = (byte)0x10;
-
- System.arraycopy(ObexHelper.computeMd5Hash(digest), 0, header.mAuthResp, 2, 16);
-
- // Add the challenge
- header.mAuthResp[18] = (byte)0x02;
- header.mAuthResp[19] = (byte)0x10;
- System.arraycopy(challenge, 0, header.mAuthResp, 20, 16);
-
- return true;
- }
-
- /**
- * Called when the server received an authentication response header. This
- * will cause the authenticator to handle the authentication response.
- * @param authResp the authentication response
- * @return <code>true</code> if the response passed; <code>false</code> if
- * the response failed
- */
- public boolean handleAuthResp(byte[] authResp) {
- if (mAuthenticator == null) {
- return false;
- }
- // get the correct password from the application
- byte[] correctPassword = mAuthenticator.onAuthenticationResponse(ObexHelper.getTagValue(
- (byte)0x01, authResp));
- if (correctPassword == null) {
- return false;
- }
-
- byte[] temp = new byte[correctPassword.length + 16];
-
- System.arraycopy(mChallengeDigest, 0, temp, 0, 16);
- System.arraycopy(correctPassword, 0, temp, 16, correctPassword.length);
-
- byte[] correctResponse = ObexHelper.computeMd5Hash(temp);
- byte[] actualResponse = ObexHelper.getTagValue((byte)0x00, authResp);
-
- // compare the MD5 hash array .
- for (int i = 0; i < 16; i++) {
- if (correctResponse[i] != actualResponse[i]) {
- return false;
- }
- }
-
- return true;
- }
-}
diff --git a/obex/javax/obex/ObexTransport.java b/obex/javax/obex/ObexTransport.java
deleted file mode 100644
index 4cef0b3..0000000
--- a/obex/javax/obex/ObexTransport.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Copyright (c) 2008-2009, Motorola, Inc.
- *
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of the Motorola, Inc. nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-package javax.obex;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-
-/**
- * The <code>ObexTransport</code> interface defines the underlying transport
- * connection which carries the OBEX protocol( such as TCP, RFCOMM device file
- * exposed by Bluetooth or USB in kernel, RFCOMM socket emulated in Android
- * platform, Irda). This interface provides an abstract layer to be used by the
- * <code>ObexConnection</code>. Each kind of medium shall have its own
- * implementation to wrap and follow the same interface.
- * <P>
- * See section 1.2.2 of IrDA Object Exchange Protocol specification.
- * <P>
- * Different kind of medium may have different construction - for example, the
- * RFCOMM device file medium may be constructed from a file descriptor or simply
- * a string while the TCP medium usually from a socket.
- * @hide
- */
-public interface ObexTransport {
-
- void create() throws IOException;
-
- void listen() throws IOException;
-
- void close() throws IOException;
-
- void connect() throws IOException;
-
- void disconnect() throws IOException;
-
- InputStream openInputStream() throws IOException;
-
- OutputStream openOutputStream() throws IOException;
-
- DataInputStream openDataInputStream() throws IOException;
-
- DataOutputStream openDataOutputStream() throws IOException;
-
- /**
- * Must return the maximum allowed OBEX packet that can be sent over
- * the transport. For L2CAP this will be the Max SDU reported by the
- * peer device.
- * The returned value will be used to set the outgoing OBEX packet
- * size. Therefore this value shall not change.
- * For RFCOMM or other transport types where the OBEX packets size
- * is unrelated to the transport packet size, return -1;
- * Exception can be made (like PBAP transport) with a smaller value
- * to avoid bad effect on other profiles using the RFCOMM;
- * @return the maximum allowed OBEX packet that can be send over
- * the transport. Or -1 in case of don't care.
- */
- int getMaxTransmitPacketSize();
-
- /**
- * Must return the maximum allowed OBEX packet that can be received over
- * the transport. For L2CAP this will be the Max SDU configured for the
- * L2CAP channel.
- * The returned value will be used to validate the incoming packet size
- * values.
- * For RFCOMM or other transport types where the OBEX packets size
- * is unrelated to the transport packet size, return -1;
- * @return the maximum allowed OBEX packet that can be send over
- * the transport. Or -1 in case of don't care.
- */
- int getMaxReceivePacketSize();
-
- /**
- * Shall return true if the transport in use supports SRM.
- * @return
- * <code>true</code> if SRM operation is supported, and is to be enabled.
- * <code>false</code> if SRM operations are not supported, or should not be used.
- */
- boolean isSrmSupported();
-
-
-}
diff --git a/obex/javax/obex/Operation.java b/obex/javax/obex/Operation.java
deleted file mode 100644
index 5b4d5ac..0000000
--- a/obex/javax/obex/Operation.java
+++ /dev/null
@@ -1,183 +0,0 @@
-/*
- * Copyright (c) 2008-2009, Motorola, Inc.
- *
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of the Motorola, Inc. nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-package javax.obex;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-
-/**
- * The <code>Operation</code> interface provides ways to manipulate a single
- * OBEX PUT or GET operation. The implementation of this interface sends OBEX
- * packets as they are built. If during the operation the peer in the operation
- * ends the operation, an <code>IOException</code> is thrown on the next read
- * from the input stream, write to the output stream, or call to
- * <code>sendHeaders()</code>.
- * <P>
- * <STRONG>Definition of methods inherited from <code>ContentConnection</code>
- * </STRONG>
- * <P>
- * <code>getEncoding()</code> will always return <code>null</code>. <BR>
- * <code>getLength()</code> will return the length specified by the OBEX Length
- * header or -1 if the OBEX Length header was not included. <BR>
- * <code>getType()</code> will return the value specified in the OBEX Type
- * header or <code>null</code> if the OBEX Type header was not included.<BR>
- * <P>
- * <STRONG>How Headers are Handled</STRONG>
- * <P>
- * As headers are received, they may be retrieved through the
- * <code>getReceivedHeaders()</code> method. If new headers are set during the
- * operation, the new headers will be sent during the next packet exchange.
- * <P>
- * <STRONG>PUT example</STRONG>
- * <P>
- * <PRE>
- * void putObjectViaOBEX(ClientSession conn, HeaderSet head, byte[] obj) throws IOException {
- * // Include the length header
- * head.setHeader(head.LENGTH, new Long(obj.length));
- * // Initiate the PUT request
- * Operation op = conn.put(head);
- * // Open the output stream to put the object to it
- * DataOutputStream out = op.openDataOutputStream();
- * // Send the object to the server
- * out.write(obj);
- * // End the transaction
- * out.close();
- * op.close();
- * }
- * </PRE>
- * <P>
- * <STRONG>GET example</STRONG>
- * <P>
- * <PRE>
- * byte[] getObjectViaOBEX(ClientSession conn, HeaderSet head) throws IOException {
- * // Send the initial GET request to the server
- * Operation op = conn.get(head);
- * // Retrieve the length of the object being sent back
- * int length = op.getLength();
- * // Create space for the object
- * byte[] obj = new byte[length];
- * // Get the object from the input stream
- * DataInputStream in = trans.openDataInputStream();
- * in.read(obj);
- * // End the transaction
- * in.close();
- * op.close();
- * return obj;
- * }
- * </PRE>
- *
- * <H3>Client PUT Operation Flow</H3> For PUT operations, a call to
- * <code>close()</code> the <code>OutputStream</code> returned from
- * <code>openOutputStream()</code> or <code>openDataOutputStream()</code> will
- * signal that the request is done. (In OBEX terms, the End-Of-Body header
- * should be sent and the final bit in the request will be set.) At this point,
- * the reply from the server may begin to be processed. A call to
- * <code>getResponseCode()</code> will do an implicit close on the
- * <code>OutputStream</code> and therefore signal that the request is done.
- * <H3>Client GET Operation Flow</H3> For GET operation, a call to
- * <code>openInputStream()</code> or <code>openDataInputStream()</code> will
- * signal that the request is done. (In OBEX terms, the final bit in the request
- * will be set.) A call to <code>getResponseCode()</code> will cause an implicit
- * close on the <code>InputStream</code>. No further data may be read at this
- * point.
- * @hide
- */
-public interface Operation {
-
- /**
- * Sends an ABORT message to the server. By calling this method, the
- * corresponding input and output streams will be closed along with this
- * object. No headers are sent in the abort request. This will end the
- * operation since <code>close()</code> will be called by this method.
- * @throws IOException if the transaction has already ended or if an OBEX
- * server calls this method
- */
- void abort() throws IOException;
-
- /**
- * Returns the headers that have been received during the operation.
- * Modifying the object returned has no effect on the headers that are sent
- * or retrieved.
- * @return the headers received during this <code>Operation</code>
- * @throws IOException if this <code>Operation</code> has been closed
- */
- HeaderSet getReceivedHeader() throws IOException;
-
- /**
- * Specifies the headers that should be sent in the next OBEX message that
- * is sent.
- * @param headers the headers to send in the next message
- * @throws IOException if this <code>Operation</code> has been closed or the
- * transaction has ended and no further messages will be exchanged
- * @throws IllegalArgumentException if <code>headers</code> was not created
- * by a call to <code>ServerRequestHandler.createHeaderSet()</code>
- * or <code>ClientSession.createHeaderSet()</code>
- * @throws NullPointerException if <code>headers</code> if <code>null</code>
- */
- void sendHeaders(HeaderSet headers) throws IOException;
-
- /**
- * Returns the response code received from the server. Response codes are
- * defined in the <code>ResponseCodes</code> class.
- * @see ResponseCodes
- * @return the response code retrieved from the server
- * @throws IOException if an error occurred in the transport layer during
- * the transaction; if this object was created by an OBEX server
- */
- int getResponseCode() throws IOException;
-
- String getEncoding();
-
- long getLength();
-
- int getHeaderLength();
-
- String getType();
-
- InputStream openInputStream() throws IOException;
-
- DataInputStream openDataInputStream() throws IOException;
-
- OutputStream openOutputStream() throws IOException;
-
- DataOutputStream openDataOutputStream() throws IOException;
-
- void close() throws IOException;
-
- int getMaxPacketSize();
-
- public void noBodyHeader();
-}
diff --git a/obex/javax/obex/PasswordAuthentication.java b/obex/javax/obex/PasswordAuthentication.java
deleted file mode 100644
index 326b1ff..0000000
--- a/obex/javax/obex/PasswordAuthentication.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright (c) 2008-2009, Motorola, Inc.
- *
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of the Motorola, Inc. nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-package javax.obex;
-
-/**
- * This class holds user name and password combinations.
- * @hide
- */
-public final class PasswordAuthentication {
-
- private byte[] mUserName;
-
- private final byte[] mPassword;
-
- /**
- * Creates a new <code>PasswordAuthentication</code> with the user name and
- * password provided.
- * @param userName the user name to include; this may be <code>null</code>
- * @param password the password to include in the response
- * @throws NullPointerException if <code>password</code> is
- * <code>null</code>
- */
- public PasswordAuthentication(final byte[] userName, final byte[] password) {
- if (userName != null) {
- mUserName = new byte[userName.length];
- System.arraycopy(userName, 0, mUserName, 0, userName.length);
- }
-
- mPassword = new byte[password.length];
- System.arraycopy(password, 0, mPassword, 0, password.length);
- }
-
- /**
- * Retrieves the user name that was specified in the constructor. The user
- * name may be <code>null</code>.
- * @return the user name
- */
- public byte[] getUserName() {
- return mUserName;
- }
-
- /**
- * Retrieves the password.
- * @return the password
- */
- public byte[] getPassword() {
- return mPassword;
- }
-}
diff --git a/obex/javax/obex/PrivateInputStream.java b/obex/javax/obex/PrivateInputStream.java
deleted file mode 100644
index 5daee72..0000000
--- a/obex/javax/obex/PrivateInputStream.java
+++ /dev/null
@@ -1,181 +0,0 @@
-/*
- * Copyright (c) 2008-2009, Motorola, Inc.
- *
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of the Motorola, Inc. nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-package javax.obex;
-
-import java.io.InputStream;
-import java.io.IOException;
-
-/**
- * This object provides an input stream to the Operation objects used in this
- * package.
- * @hide
- */
-public final class PrivateInputStream extends InputStream {
-
- private BaseStream mParent;
-
- private byte[] mData;
-
- private int mIndex;
-
- private boolean mOpen;
-
- /**
- * Creates an input stream for the <code>Operation</code> to read from
- * @param p the connection this input stream is for
- */
- public PrivateInputStream(BaseStream p) {
- mParent = p;
- mData = new byte[0];
- mIndex = 0;
- mOpen = true;
- }
-
- /**
- * Returns the number of bytes that can be read (or skipped over) from this
- * input stream without blocking by the next caller of a method for this
- * input stream. The next caller might be the same thread or or another
- * thread.
- * @return the number of bytes that can be read from this input stream
- * without blocking
- * @throws IOException if an I/O error occurs
- */
- @Override
- public synchronized int available() throws IOException {
- ensureOpen();
- return mData.length - mIndex;
- }
-
- /**
- * Reads the next byte of data from the input stream. The value byte is
- * returned as an int in the range 0 to 255. If no byte is available because
- * the end of the stream has been reached, the value -1 is returned. This
- * method blocks until input data is available, the end of the stream is
- * detected, or an exception is thrown.
- * @return the byte read from the input stream or -1 if it reaches the end of
- * stream
- * @throws IOException if an I/O error occurs
- */
- @Override
- public synchronized int read() throws IOException {
- ensureOpen();
- while (mData.length == mIndex) {
- if (!mParent.continueOperation(true, true)) {
- return -1;
- }
- }
- return (mData[mIndex++] & 0xFF);
- }
-
- @Override
- public int read(byte[] b) throws IOException {
- return read(b, 0, b.length);
- }
-
- @Override
- public synchronized int read(byte[] b, int offset, int length) throws IOException {
-
- if (b == null) {
- throw new IOException("buffer is null");
- }
- if ((offset | length) < 0 || length > b.length - offset) {
- throw new ArrayIndexOutOfBoundsException("index outof bound");
- }
- ensureOpen();
-
- int currentDataLength = mData.length - mIndex;
- int remainReadLength = length;
- int offset1 = offset;
- int result = 0;
-
- while (currentDataLength <= remainReadLength) {
- System.arraycopy(mData, mIndex, b, offset1, currentDataLength);
- mIndex += currentDataLength;
- offset1 += currentDataLength;
- result += currentDataLength;
- remainReadLength -= currentDataLength;
-
- if (!mParent.continueOperation(true, true)) {
- return result == 0 ? -1 : result;
- }
- currentDataLength = mData.length - mIndex;
- }
- if (remainReadLength > 0) {
- System.arraycopy(mData, mIndex, b, offset1, remainReadLength);
- mIndex += remainReadLength;
- result += remainReadLength;
- }
- return result;
- }
-
- /**
- * Allows the <code>OperationImpl</code> thread to add body data to the
- * input stream.
- * @param body the data to add to the stream
- * @param start the start of the body to array to copy
- */
- public synchronized void writeBytes(byte[] body, int start) {
-
- int length = (body.length - start) + (mData.length - mIndex);
- byte[] temp = new byte[length];
-
- System.arraycopy(mData, mIndex, temp, 0, mData.length - mIndex);
- System.arraycopy(body, start, temp, mData.length - mIndex, body.length - start);
-
- mData = temp;
- mIndex = 0;
- notifyAll();
- }
-
- /**
- * Verifies that this stream is open
- * @throws IOException if the stream is not open
- */
- private void ensureOpen() throws IOException {
- mParent.ensureOpen();
- if (!mOpen) {
- throw new IOException("Input stream is closed");
- }
- }
-
- /**
- * Closes the input stream. If the input stream is already closed, do
- * nothing.
- * @throws IOException this will never happen
- */
- @Override
- public void close() throws IOException {
- mOpen = false;
- mParent.streamClosed(true);
- }
-}
diff --git a/obex/javax/obex/PrivateOutputStream.java b/obex/javax/obex/PrivateOutputStream.java
deleted file mode 100644
index 713f4ae..0000000
--- a/obex/javax/obex/PrivateOutputStream.java
+++ /dev/null
@@ -1,172 +0,0 @@
-/*
- * Copyright (c) 2008-2009, Motorola, Inc.
- *
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of the Motorola, Inc. nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-package javax.obex;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.ByteArrayOutputStream;
-
-/**
- * This object provides an output stream to the Operation objects used in this
- * package.
- * @hide
- */
-public final class PrivateOutputStream extends OutputStream {
-
- private BaseStream mParent;
-
- private ByteArrayOutputStream mArray;
-
- private boolean mOpen;
-
- private int mMaxPacketSize;
-
- /**
- * Creates an empty <code>PrivateOutputStream</code> to write to.
- * @param p the connection that this stream runs over
- */
- public PrivateOutputStream(BaseStream p, int maxSize) {
- mParent = p;
- mArray = new ByteArrayOutputStream();
- mMaxPacketSize = maxSize;
- mOpen = true;
- }
-
- /**
- * Determines how many bytes have been written to the output stream.
- * @return the number of bytes written to the output stream
- */
- public int size() {
- return mArray.size();
- }
-
- /**
- * Writes the specified byte to this output stream. The general contract for
- * write is that one byte is written to the output stream. The byte to be
- * written is the eight low-order bits of the argument b. The 24 high-order
- * bits of b are ignored.
- * @param b the byte to write
- * @throws IOException if an I/O error occurs
- */
- @Override
- public synchronized void write(int b) throws IOException {
- ensureOpen();
- mParent.ensureNotDone();
- mArray.write(b);
- if (mArray.size() == mMaxPacketSize) {
- mParent.continueOperation(true, false);
- }
- }
-
- @Override
- public void write(byte[] buffer) throws IOException {
- write(buffer, 0, buffer.length);
- }
-
- @Override
- public synchronized void write(byte[] buffer, int offset, int count) throws IOException {
- int offset1 = offset;
- int remainLength = count;
-
- if (buffer == null) {
- throw new IOException("buffer is null");
- }
- if ((offset | count) < 0 || count > buffer.length - offset) {
- throw new IndexOutOfBoundsException("index outof bound");
- }
-
- ensureOpen();
- mParent.ensureNotDone();
- while ((mArray.size() + remainLength) >= mMaxPacketSize) {
- int bufferLeft = mMaxPacketSize - mArray.size();
- mArray.write(buffer, offset1, bufferLeft);
- offset1 += bufferLeft;
- remainLength -= bufferLeft;
- mParent.continueOperation(true, false);
- }
- if (remainLength > 0) {
- mArray.write(buffer, offset1, remainLength);
- }
- }
-
- /**
- * Reads the bytes that have been written to this stream.
- * @param size the size of the array to return
- * @return the byte array that is written
- */
- public synchronized byte[] readBytes(int size) {
- if (mArray.size() > 0) {
- byte[] temp = mArray.toByteArray();
- mArray.reset();
- byte[] result = new byte[size];
- System.arraycopy(temp, 0, result, 0, size);
- if (temp.length != size) {
- mArray.write(temp, size, temp.length - size);
- }
- return result;
- } else {
- return null;
- }
- }
-
- /**
- * Verifies that this stream is open
- * @throws IOException if the stream is not open
- */
- private void ensureOpen() throws IOException {
- mParent.ensureOpen();
- if (!mOpen) {
- throw new IOException("Output stream is closed");
- }
- }
-
- /**
- * Closes the output stream. If the input stream is already closed, do
- * nothing.
- * @throws IOException this will never happen
- */
- @Override
- public void close() throws IOException {
- mOpen = false;
- mParent.streamClosed(false);
- }
-
- /**
- * Determines if the connection is closed
- * @return <code>true</code> if the connection is closed; <code>false</code>
- * if the connection is open
- */
- public boolean isClosed() {
- return !mOpen;
- }
-}
diff --git a/obex/javax/obex/ResponseCodes.java b/obex/javax/obex/ResponseCodes.java
deleted file mode 100644
index a2b9a37..0000000
--- a/obex/javax/obex/ResponseCodes.java
+++ /dev/null
@@ -1,326 +0,0 @@
-/*
- * Copyright (c) 2008-2009, Motorola, Inc.
- *
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of the Motorola, Inc. nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-package javax.obex;
-
-/**
- * The <code>ResponseCodes</code> class contains the list of valid response
- * codes a server may send to a client.
- * <P>
- * <STRONG>IMPORTANT NOTE</STRONG>
- * <P>
- * The values in this interface represent the values defined in the IrOBEX
- * specification, which is different with the HTTP specification.
- * <P>
- * <code>OBEX_DATABASE_FULL</code> and <code>OBEX_DATABASE_LOCKED</code> require
- * further description since they are not defined in HTTP. The server will send
- * an <code>OBEX_DATABASE_FULL</code> message when the client requests that
- * something be placed into a database but the database is full (cannot take
- * more data). <code>OBEX_DATABASE_LOCKED</code> will be returned when the
- * client wishes to access a database, database table, or database record that
- * has been locked.
- * @hide
- */
-public final class ResponseCodes {
-
- /**
- * Defines the OBEX CONTINUE response code.
- * <P>
- * The value of <code>OBEX_HTTP_CONTINUE</code> is 0x90 (144).
- */
- public static final int OBEX_HTTP_CONTINUE = 0x90;
-
- /**
- * Defines the OBEX SUCCESS response code.
- * <P>
- * The value of <code>OBEX_HTTP_OK</code> is 0xA0 (160).
- */
- public static final int OBEX_HTTP_OK = 0xA0;
-
- /**
- * Defines the OBEX CREATED response code.
- * <P>
- * The value of <code>OBEX_HTTP_CREATED</code> is 0xA1 (161).
- */
- public static final int OBEX_HTTP_CREATED = 0xA1;
-
- /**
- * Defines the OBEX ACCEPTED response code.
- * <P>
- * The value of <code>OBEX_HTTP_ACCEPTED</code> is 0xA2 (162).
- */
- public static final int OBEX_HTTP_ACCEPTED = 0xA2;
-
- /**
- * Defines the OBEX NON-AUTHORITATIVE INFORMATION response code.
- * <P>
- * The value of <code>OBEX_HTTP_NOT_AUTHORITATIVE</code> is 0xA3 (163).
- */
- public static final int OBEX_HTTP_NOT_AUTHORITATIVE = 0xA3;
-
- /**
- * Defines the OBEX NO CONTENT response code.
- * <P>
- * The value of <code>OBEX_HTTP_NO_CONTENT</code> is 0xA4 (164).
- */
- public static final int OBEX_HTTP_NO_CONTENT = 0xA4;
-
- /**
- * Defines the OBEX RESET CONTENT response code.
- * <P>
- * The value of <code>OBEX_HTTP_RESET</code> is 0xA5 (165).
- */
- public static final int OBEX_HTTP_RESET = 0xA5;
-
- /**
- * Defines the OBEX PARTIAL CONTENT response code.
- * <P>
- * The value of <code>OBEX_HTTP_PARTIAL</code> is 0xA6 (166).
- */
- public static final int OBEX_HTTP_PARTIAL = 0xA6;
-
- /**
- * Defines the OBEX MULTIPLE_CHOICES response code.
- * <P>
- * The value of <code>OBEX_HTTP_MULT_CHOICE</code> is 0xB0 (176).
- */
- public static final int OBEX_HTTP_MULT_CHOICE = 0xB0;
-
- /**
- * Defines the OBEX MOVED PERMANENTLY response code.
- * <P>
- * The value of <code>OBEX_HTTP_MOVED_PERM</code> is 0xB1 (177).
- */
- public static final int OBEX_HTTP_MOVED_PERM = 0xB1;
-
- /**
- * Defines the OBEX MOVED TEMPORARILY response code.
- * <P>
- * The value of <code>OBEX_HTTP_MOVED_TEMP</code> is 0xB2 (178).
- */
- public static final int OBEX_HTTP_MOVED_TEMP = 0xB2;
-
- /**
- * Defines the OBEX SEE OTHER response code.
- * <P>
- * The value of <code>OBEX_HTTP_SEE_OTHER</code> is 0xB3 (179).
- */
- public static final int OBEX_HTTP_SEE_OTHER = 0xB3;
-
- /**
- * Defines the OBEX NOT MODIFIED response code.
- * <P>
- * The value of <code>OBEX_HTTP_NOT_MODIFIED</code> is 0xB4 (180).
- */
- public static final int OBEX_HTTP_NOT_MODIFIED = 0xB4;
-
- /**
- * Defines the OBEX USE PROXY response code.
- * <P>
- * The value of <code>OBEX_HTTP_USE_PROXY</code> is 0xB5 (181).
- */
- public static final int OBEX_HTTP_USE_PROXY = 0xB5;
-
- /**
- * Defines the OBEX BAD REQUEST response code.
- * <P>
- * The value of <code>OBEX_HTTP_BAD_REQUEST</code> is 0xC0 (192).
- */
- public static final int OBEX_HTTP_BAD_REQUEST = 0xC0;
-
- /**
- * Defines the OBEX UNAUTHORIZED response code.
- * <P>
- * The value of <code>OBEX_HTTP_UNAUTHORIZED</code> is 0xC1 (193).
- */
- public static final int OBEX_HTTP_UNAUTHORIZED = 0xC1;
-
- /**
- * Defines the OBEX PAYMENT REQUIRED response code.
- * <P>
- * The value of <code>OBEX_HTTP_PAYMENT_REQUIRED</code> is 0xC2 (194).
- */
- public static final int OBEX_HTTP_PAYMENT_REQUIRED = 0xC2;
-
- /**
- * Defines the OBEX FORBIDDEN response code.
- * <P>
- * The value of <code>OBEX_HTTP_FORBIDDEN</code> is 0xC3 (195).
- */
- public static final int OBEX_HTTP_FORBIDDEN = 0xC3;
-
- /**
- * Defines the OBEX NOT FOUND response code.
- * <P>
- * The value of <code>OBEX_HTTP_NOT_FOUND</code> is 0xC4 (196).
- */
- public static final int OBEX_HTTP_NOT_FOUND = 0xC4;
-
- /**
- * Defines the OBEX METHOD NOT ALLOWED response code.
- * <P>
- * The value of <code>OBEX_HTTP_BAD_METHOD</code> is 0xC5 (197).
- */
- public static final int OBEX_HTTP_BAD_METHOD = 0xC5;
-
- /**
- * Defines the OBEX NOT ACCEPTABLE response code.
- * <P>
- * The value of <code>OBEX_HTTP_NOT_ACCEPTABLE</code> is 0xC6 (198).
- */
- public static final int OBEX_HTTP_NOT_ACCEPTABLE = 0xC6;
-
- /**
- * Defines the OBEX PROXY AUTHENTICATION REQUIRED response code.
- * <P>
- * The value of <code>OBEX_HTTP_PROXY_AUTH</code> is 0xC7 (199).
- */
- public static final int OBEX_HTTP_PROXY_AUTH = 0xC7;
-
- /**
- * Defines the OBEX REQUEST TIME OUT response code.
- * <P>
- * The value of <code>OBEX_HTTP_TIMEOUT</code> is 0xC8 (200).
- */
- public static final int OBEX_HTTP_TIMEOUT = 0xC8;
-
- /**
- * Defines the OBEX METHOD CONFLICT response code.
- * <P>
- * The value of <code>OBEX_HTTP_CONFLICT</code> is 0xC9 (201).
- */
- public static final int OBEX_HTTP_CONFLICT = 0xC9;
-
- /**
- * Defines the OBEX METHOD GONE response code.
- * <P>
- * The value of <code>OBEX_HTTP_GONE</code> is 0xCA (202).
- */
- public static final int OBEX_HTTP_GONE = 0xCA;
-
- /**
- * Defines the OBEX METHOD LENGTH REQUIRED response code.
- * <P>
- * The value of <code>OBEX_HTTP_LENGTH_REQUIRED</code> is 0xCB (203).
- */
- public static final int OBEX_HTTP_LENGTH_REQUIRED = 0xCB;
-
- /**
- * Defines the OBEX PRECONDITION FAILED response code.
- * <P>
- * The value of <code>OBEX_HTTP_PRECON_FAILED</code> is 0xCC (204).
- */
- public static final int OBEX_HTTP_PRECON_FAILED = 0xCC;
-
- /**
- * Defines the OBEX REQUESTED ENTITY TOO LARGE response code.
- * <P>
- * The value of <code>OBEX_HTTP_ENTITY_TOO_LARGE</code> is 0xCD (205).
- */
- public static final int OBEX_HTTP_ENTITY_TOO_LARGE = 0xCD;
-
- /**
- * Defines the OBEX REQUESTED URL TOO LARGE response code.
- * <P>
- * The value of <code>OBEX_HTTP_REQ_TOO_LARGE</code> is 0xCE (206).
- */
- public static final int OBEX_HTTP_REQ_TOO_LARGE = 0xCE;
-
- /**
- * Defines the OBEX UNSUPPORTED MEDIA TYPE response code.
- * <P>
- * The value of <code>OBEX_HTTP_UNSUPPORTED_TYPE</code> is 0xCF (207).
- */
- public static final int OBEX_HTTP_UNSUPPORTED_TYPE = 0xCF;
-
- /**
- * Defines the OBEX INTERNAL SERVER ERROR response code.
- * <P>
- * The value of <code>OBEX_HTTP_INTERNAL_ERROR</code> is 0xD0 (208).
- */
- public static final int OBEX_HTTP_INTERNAL_ERROR = 0xD0;
-
- /**
- * Defines the OBEX NOT IMPLEMENTED response code.
- * <P>
- * The value of <code>OBEX_HTTP_NOT_IMPLEMENTED</code> is 0xD1 (209).
- */
- public static final int OBEX_HTTP_NOT_IMPLEMENTED = 0xD1;
-
- /**
- * Defines the OBEX BAD GATEWAY response code.
- * <P>
- * The value of <code>OBEX_HTTP_BAD_GATEWAY</code> is 0xD2 (210).
- */
- public static final int OBEX_HTTP_BAD_GATEWAY = 0xD2;
-
- /**
- * Defines the OBEX SERVICE UNAVAILABLE response code.
- * <P>
- * The value of <code>OBEX_HTTP_UNAVAILABLE</code> is 0xD3 (211).
- */
- public static final int OBEX_HTTP_UNAVAILABLE = 0xD3;
-
- /**
- * Defines the OBEX GATEWAY TIMEOUT response code.
- * <P>
- * The value of <code>OBEX_HTTP_GATEWAY_TIMEOUT</code> is 0xD4 (212).
- */
- public static final int OBEX_HTTP_GATEWAY_TIMEOUT = 0xD4;
-
- /**
- * Defines the OBEX HTTP VERSION NOT SUPPORTED response code.
- * <P>
- * The value of <code>OBEX_HTTP_VERSION</code> is 0xD5 (213).
- */
- public static final int OBEX_HTTP_VERSION = 0xD5;
-
- /**
- * Defines the OBEX DATABASE FULL response code.
- * <P>
- * The value of <code>OBEX_DATABASE_FULL</code> is 0xE0 (224).
- */
- public static final int OBEX_DATABASE_FULL = 0xE0;
-
- /**
- * Defines the OBEX DATABASE LOCKED response code.
- * <P>
- * The value of <code>OBEX_DATABASE_LOCKED</code> is 0xE1 (225).
- */
- public static final int OBEX_DATABASE_LOCKED = 0xE1;
-
- /**
- * Constructor does nothing.
- */
- private ResponseCodes() {
- }
-}
diff --git a/obex/javax/obex/ServerOperation.java b/obex/javax/obex/ServerOperation.java
deleted file mode 100644
index 15ea367..0000000
--- a/obex/javax/obex/ServerOperation.java
+++ /dev/null
@@ -1,861 +0,0 @@
-/* Copyright (c) 2015 The Android Open Source Project
- * Copyright (C) 2015 Samsung LSI
- * Copyright (c) 2008-2009, Motorola, Inc.
- *
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of the Motorola, Inc. nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-package javax.obex;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.DataInputStream;
-import java.io.OutputStream;
-import java.io.DataOutputStream;
-import java.io.ByteArrayOutputStream;
-
-import android.util.Log;
-
-/**
- * This class implements the Operation interface for server side connections.
- * <P>
- * <STRONG>Request Codes</STRONG> There are four different request codes that
- * are in this class. 0x02 is a PUT request that signals that the request is not
- * complete and requires an additional OBEX packet. 0x82 is a PUT request that
- * says that request is complete. In this case, the server can begin sending the
- * response. The 0x03 is a GET request that signals that the request is not
- * finished. When the server receives a 0x83, the client is signaling the server
- * that it is done with its request. TODO: Extend the ClientOperation and reuse
- * the methods defined TODO: in that class.
- * @hide
- */
-public final class ServerOperation implements Operation, BaseStream {
-
- private static final String TAG = "ServerOperation";
-
- private static final boolean V = ObexHelper.VDBG; // Verbose debugging
-
- public boolean isAborted;
-
- public HeaderSet requestHeader;
-
- public HeaderSet replyHeader;
-
- public boolean finalBitSet;
-
- private InputStream mInput;
-
- private ServerSession mParent;
-
- private int mMaxPacketLength;
-
- private int mResponseSize;
-
- private boolean mClosed;
-
- private boolean mGetOperation;
-
- private PrivateInputStream mPrivateInput;
-
- private PrivateOutputStream mPrivateOutput;
-
- private ObexTransport mTransport;
-
- private boolean mPrivateOutputOpen;
-
- private String mExceptionString;
-
- private ServerRequestHandler mListener;
-
- private boolean mRequestFinished;
-
- private boolean mHasBody;
-
- private boolean mSendBodyHeader = true;
- // Assume SRM disabled - needs to be explicit
- // enabled by client
- private boolean mSrmEnabled = false;
- // A latch - when triggered, there is not way back ;-)
- private boolean mSrmActive = false;
- // Set to true when a SRM enable response have been send
- private boolean mSrmResponseSent = false;
- // keep waiting until final-bit is received in request
- // to handle the case where the SRM enable header is in
- // a different OBEX packet than the SRMP header.
- private boolean mSrmWaitingForRemote = true;
- // Why should we wait? - currently not exposed to apps.
- private boolean mSrmLocalWait = false;
-
- /**
- * Creates new ServerOperation
- * @param p the parent that created this object
- * @param in the input stream to read from
- * @param out the output stream to write to
- * @param request the initial request that was received from the client
- * @param maxSize the max packet size that the client will accept
- * @param listen the listener that is responding to the request
- * @throws IOException if an IO error occurs
- */
- public ServerOperation(ServerSession p, InputStream in, int request, int maxSize,
- ServerRequestHandler listen) throws IOException {
-
- isAborted = false;
- mParent = p;
- mInput = in;
- mMaxPacketLength = maxSize;
- mClosed = false;
- requestHeader = new HeaderSet();
- replyHeader = new HeaderSet();
- mPrivateInput = new PrivateInputStream(this);
- mResponseSize = 3;
- mListener = listen;
- mRequestFinished = false;
- mPrivateOutputOpen = false;
- mHasBody = false;
- ObexPacket packet;
- mTransport = p.getTransport();
-
- /*
- * Determine if this is a PUT request
- */
- if ((request == ObexHelper.OBEX_OPCODE_PUT) ||
- (request == ObexHelper.OBEX_OPCODE_PUT_FINAL)) {
- /*
- * It is a PUT request.
- */
- mGetOperation = false;
-
- /*
- * Determine if the final bit is set
- */
- if ((request & ObexHelper.OBEX_OPCODE_FINAL_BIT_MASK) == 0) {
- finalBitSet = false;
- } else {
- finalBitSet = true;
- mRequestFinished = true;
- }
- } else if ((request == ObexHelper.OBEX_OPCODE_GET) ||
- (request == ObexHelper.OBEX_OPCODE_GET_FINAL)) {
- /*
- * It is a GET request.
- */
- mGetOperation = true;
-
- // For Get request, final bit set is decided by server side logic
- finalBitSet = false;
-
- if (request == ObexHelper.OBEX_OPCODE_GET_FINAL) {
- mRequestFinished = true;
- }
- } else {
- throw new IOException("ServerOperation can not handle such request");
- }
-
- packet = ObexPacket.read(request, mInput);
-
- /*
- * Determine if the packet length is larger than this device can receive
- */
- if (packet.mLength > ObexHelper.getMaxRxPacketSize(mTransport)) {
- mParent.sendResponse(ResponseCodes.OBEX_HTTP_REQ_TOO_LARGE, null);
- throw new IOException("Packet received was too large. Length: "
- + packet.mLength + " maxLength: " + ObexHelper.getMaxRxPacketSize(mTransport));
- }
-
- /*
- * Determine if any headers were sent in the initial request
- */
- if (packet.mLength > 3) {
- if(!handleObexPacket(packet)) {
- return;
- }
- /* Don't Pre-Send continue when Remote requested for SRM
- * Let the Application confirm.
- */
- if (V) Log.v(TAG, "Get App confirmation if SRM ENABLED case: " + mSrmEnabled
- + " not hasBody case: " + mHasBody);
- if (!mHasBody && !mSrmEnabled) {
- while ((!mGetOperation) && (!finalBitSet)) {
- sendReply(ResponseCodes.OBEX_HTTP_CONTINUE);
- if (mPrivateInput.available() > 0) {
- break;
- }
- }
- }
- }
- /* Don't Pre-Send continue when Remote requested for SRM
- * Let the Application confirm.
- */
- if (V) Log.v(TAG, "Get App confirmation if SRM ENABLED case: " + mSrmEnabled
- + " not finalPacket: " + finalBitSet + " not GETOp Case: " + mGetOperation);
- while ((!mSrmEnabled) && (!mGetOperation) && (!finalBitSet)
- && (mPrivateInput.available() == 0)) {
- sendReply(ResponseCodes.OBEX_HTTP_CONTINUE);
- if (mPrivateInput.available() > 0) {
- break;
- }
- }
-
- // wait for get request finished !!!!
- while (mGetOperation && !mRequestFinished) {
- sendReply(ResponseCodes.OBEX_HTTP_CONTINUE);
- }
- }
-
- /**
- * Parse headers and update member variables
- * @param packet the received obex packet
- * @return false for failing authentication - and a OBEX_HTTP_UNAUTHORIZED
- * response have been send. Else true.
- * @throws IOException
- */
- private boolean handleObexPacket(ObexPacket packet) throws IOException {
- byte[] body = updateRequestHeaders(packet);
-
- if (body != null) {
- mHasBody = true;
- }
- if (mListener.getConnectionId() != -1 && requestHeader.mConnectionID != null) {
- mListener.setConnectionId(ObexHelper
- .convertToLong(requestHeader.mConnectionID));
- } else {
- mListener.setConnectionId(1);
- }
-
- if (requestHeader.mAuthResp != null) {
- if (!mParent.handleAuthResp(requestHeader.mAuthResp)) {
- mExceptionString = "Authentication Failed";
- mParent.sendResponse(ResponseCodes.OBEX_HTTP_UNAUTHORIZED, null);
- mClosed = true;
- requestHeader.mAuthResp = null;
- return false;
- }
- requestHeader.mAuthResp = null;
- }
-
- if (requestHeader.mAuthChall != null) {
- mParent.handleAuthChall(requestHeader);
- // send the auhtResp to the client
- replyHeader.mAuthResp = new byte[requestHeader.mAuthResp.length];
- System.arraycopy(requestHeader.mAuthResp, 0, replyHeader.mAuthResp, 0,
- replyHeader.mAuthResp.length);
- requestHeader.mAuthResp = null;
- requestHeader.mAuthChall = null;
- }
-
- if (body != null) {
- mPrivateInput.writeBytes(body, 1);
- }
- return true;
- }
-
- /**
- * Update the request header set, and sniff on SRM headers to update local state.
- * @param data the OBEX packet data
- * @return any bytes in a body/end-of-body header returned by {@link ObexHelper.updateHeaderSet}
- * @throws IOException
- */
- private byte[] updateRequestHeaders(ObexPacket packet) throws IOException {
- byte[] body = null;
- if (packet.mPayload != null) {
- body = ObexHelper.updateHeaderSet(requestHeader, packet.mPayload);
- }
- Byte srmMode = (Byte)requestHeader.getHeader(HeaderSet.SINGLE_RESPONSE_MODE);
- if(mTransport.isSrmSupported() && srmMode != null
- && srmMode == ObexHelper.OBEX_SRM_ENABLE) {
- mSrmEnabled = true;
- if(V) Log.d(TAG,"SRM is now ENABLED (but not active) for this operation");
- }
- checkForSrmWait(packet.mHeaderId);
- if((!mSrmWaitingForRemote) && (mSrmEnabled)) {
- if(V) Log.d(TAG,"SRM is now ACTIVE for this operation");
- mSrmActive = true;
- }
- return body;
- }
-
- /**
- * Call this only when a complete request have been received.
- * (This is not optimal, but the current design is not really suited to
- * the way SRM is specified.)
- */
- private void checkForSrmWait(int headerId){
- if (mSrmEnabled && (headerId == ObexHelper.OBEX_OPCODE_GET
- || headerId == ObexHelper.OBEX_OPCODE_GET_FINAL
- || headerId == ObexHelper.OBEX_OPCODE_PUT)) {
- try {
- mSrmWaitingForRemote = false;
- Byte srmp = (Byte)requestHeader.getHeader(HeaderSet.SINGLE_RESPONSE_MODE_PARAMETER);
- if(srmp != null && srmp == ObexHelper.OBEX_SRMP_WAIT) {
- mSrmWaitingForRemote = true;
- // Clear the wait header, as the absents of the header when the final bit is set
- // indicates don't wait.
- requestHeader.setHeader(HeaderSet.SINGLE_RESPONSE_MODE_PARAMETER, null);
- }
- } catch (IOException e) {if(V){Log.w(TAG,"Exception while extracting header",e);}}
- }
- }
-
- public boolean isValidBody() {
- return mHasBody;
- }
-
- /**
- * Determines if the operation should continue or should wait. If it should
- * continue, this method will continue the operation.
- * @param sendEmpty if <code>true</code> then this will continue the
- * operation even if no headers will be sent; if <code>false</code>
- * then this method will only continue the operation if there are
- * headers to send
- * @param inStream if<code>true</code> the stream is input stream, otherwise
- * output stream
- * @return <code>true</code> if the operation was completed;
- * <code>false</code> if no operation took place
- */
- public synchronized boolean continueOperation(boolean sendEmpty, boolean inStream)
- throws IOException {
- if (!mGetOperation) {
- if (!finalBitSet) {
- if (sendEmpty) {
- sendReply(ResponseCodes.OBEX_HTTP_CONTINUE);
- return true;
- } else {
- if ((mResponseSize > 3) || (mPrivateOutput.size() > 0)) {
- sendReply(ResponseCodes.OBEX_HTTP_CONTINUE);
- return true;
- } else {
- return false;
- }
- }
- } else {
- return false;
- }
- } else {
- sendReply(ResponseCodes.OBEX_HTTP_CONTINUE);
- return true;
- }
- }
-
- /**
- * Sends a reply to the client. If the reply is a OBEX_HTTP_CONTINUE, it
- * will wait for a response from the client before ending unless SRM is active.
- * @param type the response code to send back to the client
- * @return <code>true</code> if the final bit was not set on the reply;
- * <code>false</code> if no reply was received because the operation
- * ended, an abort was received, the final bit was set in the
- * reply or SRM is active.
- * @throws IOException if an IO error occurs
- */
- public synchronized boolean sendReply(int type) throws IOException {
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- boolean skipSend = false;
- boolean skipReceive = false;
- boolean srmRespSendPending = false;
-
- long id = mListener.getConnectionId();
- if (id == -1) {
- replyHeader.mConnectionID = null;
- } else {
- replyHeader.mConnectionID = ObexHelper.convertToByteArray(id);
- }
-
- if(mSrmEnabled && !mSrmResponseSent) {
- // As we are not ensured that the SRM enable is in the first OBEX packet
- // We must check for each reply.
- if(V)Log.v(TAG, "mSrmEnabled==true, sending SRM enable response.");
- replyHeader.setHeader(HeaderSet.SINGLE_RESPONSE_MODE, (byte)ObexHelper.OBEX_SRM_ENABLE);
- srmRespSendPending = true;
- }
-
- if(mSrmEnabled && !mGetOperation && mSrmLocalWait) {
- replyHeader.setHeader(HeaderSet.SINGLE_RESPONSE_MODE, (byte)ObexHelper.OBEX_SRMP_WAIT);
- }
-
- byte[] headerArray = ObexHelper.createHeader(replyHeader, true); // This clears the headers
- int bodyLength = -1;
- int orginalBodyLength = -1;
-
- if (mPrivateOutput != null) {
- bodyLength = mPrivateOutput.size();
- orginalBodyLength = bodyLength;
- }
-
- if ((ObexHelper.BASE_PACKET_LENGTH + headerArray.length) > mMaxPacketLength) {
-
- int end = 0;
- int start = 0;
-
- while (end != headerArray.length) {
- end = ObexHelper.findHeaderEnd(headerArray, start, mMaxPacketLength
- - ObexHelper.BASE_PACKET_LENGTH);
- if (end == -1) {
-
- mClosed = true;
-
- if (mPrivateInput != null) {
- mPrivateInput.close();
- }
-
- if (mPrivateOutput != null) {
- mPrivateOutput.close();
- }
- mParent.sendResponse(ResponseCodes.OBEX_HTTP_INTERNAL_ERROR, null);
- throw new IOException("OBEX Packet exceeds max packet size");
- }
- byte[] sendHeader = new byte[end - start];
- System.arraycopy(headerArray, start, sendHeader, 0, sendHeader.length);
-
- mParent.sendResponse(type, sendHeader);
- start = end;
- }
-
- if (bodyLength > 0) {
- return true;
- } else {
- return false;
- }
-
- } else {
- out.write(headerArray);
- }
-
- // For Get operation: if response code is OBEX_HTTP_OK, then this is the
- // last packet; so set finalBitSet to true.
- if (mGetOperation && type == ResponseCodes.OBEX_HTTP_OK) {
- finalBitSet = true;
- }
-
- if(mSrmActive) {
- if(!mGetOperation && type == ResponseCodes.OBEX_HTTP_CONTINUE &&
- mSrmResponseSent == true) {
- // we are in the middle of a SRM PUT operation, don't send a continue.
- skipSend = true;
- } else if(mGetOperation && mRequestFinished == false && mSrmResponseSent == true) {
- // We are still receiving the get request, receive, but don't send continue.
- skipSend = true;
- } else if(mGetOperation && mRequestFinished == true) {
- // All done receiving the GET request, send data to the client, without
- // expecting a continue.
- skipReceive = true;
- }
- if(V)Log.v(TAG, "type==" + type + " skipSend==" + skipSend
- + " skipReceive==" + skipReceive);
- }
- if(srmRespSendPending) {
- if(V)Log.v(TAG,
- "SRM Enabled (srmRespSendPending == true)- sending SRM Enable response");
- mSrmResponseSent = true;
- }
-
- if ((finalBitSet) || (headerArray.length < (mMaxPacketLength - 20))) {
- if (bodyLength > 0) {
- /*
- * Determine if I can send the whole body or just part of
- * the body. Remember that there is the 3 bytes for the
- * response message and 3 bytes for the header ID and length
- */
- if (bodyLength > (mMaxPacketLength - headerArray.length - 6)) {
- bodyLength = mMaxPacketLength - headerArray.length - 6;
- }
-
- byte[] body = mPrivateOutput.readBytes(bodyLength);
-
- /*
- * Since this is a put request if the final bit is set or
- * the output stream is closed we need to send the 0x49
- * (End of Body) otherwise, we need to send 0x48 (Body)
- */
- if ((finalBitSet) || (mPrivateOutput.isClosed())) {
- if(mSendBodyHeader == true) {
- out.write(0x49);
- bodyLength += 3;
- out.write((byte)(bodyLength >> 8));
- out.write((byte)bodyLength);
- out.write(body);
- }
- } else {
- if(mSendBodyHeader == true) {
- out.write(0x48);
- bodyLength += 3;
- out.write((byte)(bodyLength >> 8));
- out.write((byte)bodyLength);
- out.write(body);
- }
- }
-
- }
- }
-
- if ((finalBitSet) && (type == ResponseCodes.OBEX_HTTP_OK) && (orginalBodyLength <= 0)) {
- if(mSendBodyHeader) {
- out.write(0x49);
- orginalBodyLength = 3;
- out.write((byte)(orginalBodyLength >> 8));
- out.write((byte)orginalBodyLength);
- }
- }
-
- if(skipSend == false) {
- mResponseSize = 3;
- mParent.sendResponse(type, out.toByteArray());
- }
-
- if (type == ResponseCodes.OBEX_HTTP_CONTINUE) {
-
- if(mGetOperation && skipReceive) {
- // Here we need to check for and handle abort (throw an exception).
- // Any other signal received should be discarded silently (only on server side)
- checkSrmRemoteAbort();
- } else {
- // Receive and handle data (only send reply if !skipSend)
- // Read a complete OBEX Packet
- ObexPacket packet = ObexPacket.read(mInput);
-
- int headerId = packet.mHeaderId;
- if ((headerId != ObexHelper.OBEX_OPCODE_PUT)
- && (headerId != ObexHelper.OBEX_OPCODE_PUT_FINAL)
- && (headerId != ObexHelper.OBEX_OPCODE_GET)
- && (headerId != ObexHelper.OBEX_OPCODE_GET_FINAL)) {
-
- /*
- * Determine if an ABORT was sent as the reply
- */
- if (headerId == ObexHelper.OBEX_OPCODE_ABORT) {
- handleRemoteAbort();
- } else {
- // TODO:shall we send this if it occurs during SRM? Errata on the subject
- mParent.sendResponse(ResponseCodes.OBEX_HTTP_BAD_REQUEST, null);
- mClosed = true;
- mExceptionString = "Bad Request Received";
- throw new IOException("Bad Request Received");
- }
- } else {
-
- if ((headerId == ObexHelper.OBEX_OPCODE_PUT_FINAL)) {
- finalBitSet = true;
- } else if (headerId == ObexHelper.OBEX_OPCODE_GET_FINAL) {
- mRequestFinished = true;
- }
-
- /*
- * Determine if the packet length is larger than the negotiated packet size
- */
- if (packet.mLength > ObexHelper.getMaxRxPacketSize(mTransport)) {
- mParent.sendResponse(ResponseCodes.OBEX_HTTP_REQ_TOO_LARGE, null);
- throw new IOException("Packet received was too large");
- }
-
- /*
- * Determine if any headers were sent in the initial request
- */
- if (packet.mLength > 3 || (mSrmEnabled && packet.mLength == 3)) {
- if(handleObexPacket(packet) == false) {
- return false;
- }
- }
- }
-
- }
- return true;
- } else {
- return false;
- }
- }
-
- /**
- * This method will look for an abort from the peer during a SRM transfer.
- * The function will not block if no data has been received from the remote device.
- * If data have been received, the function will block while reading the incoming
- * OBEX package.
- * An Abort request will be handled, and cause an IOException("Abort Received").
- * Other messages will be discarded silently as per GOEP specification.
- * @throws IOException if an abort request have been received.
- * TODO: I think this is an error in the specification. If we discard other messages,
- * the peer device will most likely stall, as it will not receive the expected
- * response for the message...
- * I'm not sure how to understand "Receipt of invalid or unexpected SRM or SRMP
- * header values shall be ignored by the receiving device."
- * If any signal is received during an active SRM transfer it is unexpected regardless
- * whether or not it contains SRM/SRMP headers...
- */
- private void checkSrmRemoteAbort() throws IOException {
- if(mInput.available() > 0) {
- ObexPacket packet = ObexPacket.read(mInput);
- /*
- * Determine if an ABORT was sent as the reply
- */
- if (packet.mHeaderId == ObexHelper.OBEX_OPCODE_ABORT) {
- handleRemoteAbort();
- } else {
- // TODO: should we throw an exception here anyway? - don't see how to
- // ignore SRM/SRMP headers without ignoring the complete signal
- // (in this particular case).
- Log.w(TAG, "Received unexpected request from client - discarding...\n"
- + " headerId: " + packet.mHeaderId + " length: " + packet.mLength);
- }
- }
- }
-
- private void handleRemoteAbort() throws IOException {
- /* TODO: To increase the speed of the abort operation in SRM, we need
- * to be able to flush the L2CAP queue for the PSM in use.
- * This could be implemented by introducing a control
- * message to be send over the socket, that in the abort case
- * could carry a flush command. */
- mParent.sendResponse(ResponseCodes.OBEX_HTTP_OK, null);
- mClosed = true;
- isAborted = true;
- mExceptionString = "Abort Received";
- throw new IOException("Abort Received");
- }
-
- /**
- * Sends an ABORT message to the server. By calling this method, the
- * corresponding input and output streams will be closed along with this
- * object.
- * @throws IOException if the transaction has already ended or if an OBEX
- * server called this method
- */
- public void abort() throws IOException {
- throw new IOException("Called from a server");
- }
-
- /**
- * Returns the headers that have been received during the operation.
- * Modifying the object returned has no effect on the headers that are sent
- * or retrieved.
- * @return the headers received during this <code>Operation</code>
- * @throws IOException if this <code>Operation</code> has been closed
- */
- public HeaderSet getReceivedHeader() throws IOException {
- ensureOpen();
- return requestHeader;
- }
-
- /**
- * Specifies the headers that should be sent in the next OBEX message that
- * is sent.
- * @param headers the headers to send in the next message
- * @throws IOException if this <code>Operation</code> has been closed or the
- * transaction has ended and no further messages will be exchanged
- * @throws IllegalArgumentException if <code>headers</code> was not created
- * by a call to <code>ServerRequestHandler.createHeaderSet()</code>
- */
- public void sendHeaders(HeaderSet headers) throws IOException {
- ensureOpen();
-
- if (headers == null) {
- throw new IOException("Headers may not be null");
- }
-
- int[] headerList = headers.getHeaderList();
- if (headerList != null) {
- for (int i = 0; i < headerList.length; i++) {
- replyHeader.setHeader(headerList[i], headers.getHeader(headerList[i]));
- }
-
- }
- }
-
- /**
- * Retrieves the response code retrieved from the server. Response codes are
- * defined in the <code>ResponseCodes</code> interface.
- * @return the response code retrieved from the server
- * @throws IOException if an error occurred in the transport layer during
- * the transaction; if this method is called on a
- * <code>HeaderSet</code> object created by calling
- * <code>createHeaderSet</code> in a <code>ClientSession</code>
- * object; if this is called from a server
- */
- public int getResponseCode() throws IOException {
- throw new IOException("Called from a server");
- }
-
- /**
- * Always returns <code>null</code>
- * @return <code>null</code>
- */
- public String getEncoding() {
- return null;
- }
-
- /**
- * Returns the type of content that the resource connected to is providing.
- * E.g. if the connection is via HTTP, then the value of the content-type
- * header field is returned.
- * @return the content type of the resource that the URL references, or
- * <code>null</code> if not known
- */
- public String getType() {
- try {
- return (String)requestHeader.getHeader(HeaderSet.TYPE);
- } catch (IOException e) {
- return null;
- }
- }
-
- /**
- * Returns the length of the content which is being provided. E.g. if the
- * connection is via HTTP, then the value of the content-length header field
- * is returned.
- * @return the content length of the resource that this connection's URL
- * references, or -1 if the content length is not known
- */
- public long getLength() {
- try {
- Long temp = (Long)requestHeader.getHeader(HeaderSet.LENGTH);
-
- if (temp == null) {
- return -1;
- } else {
- return temp.longValue();
- }
- } catch (IOException e) {
- return -1;
- }
- }
-
- public int getMaxPacketSize() {
- return mMaxPacketLength - 6 - getHeaderLength();
- }
-
- public int getHeaderLength() {
- long id = mListener.getConnectionId();
- if (id == -1) {
- replyHeader.mConnectionID = null;
- } else {
- replyHeader.mConnectionID = ObexHelper.convertToByteArray(id);
- }
-
- byte[] headerArray = ObexHelper.createHeader(replyHeader, false);
-
- return headerArray.length;
- }
-
- /**
- * Open and return an input stream for a connection.
- * @return an input stream
- * @throws IOException if an I/O error occurs
- */
- public InputStream openInputStream() throws IOException {
- ensureOpen();
- return mPrivateInput;
- }
-
- /**
- * Open and return a data input stream for a connection.
- * @return an input stream
- * @throws IOException if an I/O error occurs
- */
- public DataInputStream openDataInputStream() throws IOException {
- return new DataInputStream(openInputStream());
- }
-
- /**
- * Open and return an output stream for a connection.
- * @return an output stream
- * @throws IOException if an I/O error occurs
- */
- public OutputStream openOutputStream() throws IOException {
- ensureOpen();
-
- if (mPrivateOutputOpen) {
- throw new IOException("no more input streams available, stream already opened");
- }
-
- if (!mRequestFinished) {
- throw new IOException("no output streams available ,request not finished");
- }
-
- if (mPrivateOutput == null) {
- mPrivateOutput = new PrivateOutputStream(this, getMaxPacketSize());
- }
- mPrivateOutputOpen = true;
- return mPrivateOutput;
- }
-
- /**
- * Open and return a data output stream for a connection.
- * @return an output stream
- * @throws IOException if an I/O error occurs
- */
- public DataOutputStream openDataOutputStream() throws IOException {
- return new DataOutputStream(openOutputStream());
- }
-
- /**
- * Closes the connection and ends the transaction
- * @throws IOException if the operation has already ended or is closed
- */
- public void close() throws IOException {
- ensureOpen();
- mClosed = true;
- }
-
- /**
- * Verifies that the connection is open and no exceptions should be thrown.
- * @throws IOException if an exception needs to be thrown
- */
- public void ensureOpen() throws IOException {
- if (mExceptionString != null) {
- throw new IOException(mExceptionString);
- }
- if (mClosed) {
- throw new IOException("Operation has already ended");
- }
- }
-
- /**
- * Verifies that additional information may be sent. In other words, the
- * operation is not done.
- * <P>
- * Included to implement the BaseStream interface only. It does not do
- * anything on the server side since the operation of the Operation object
- * is not done until after the handler returns from its method.
- * @throws IOException if the operation is completed
- */
- public void ensureNotDone() throws IOException {
- }
-
- /**
- * Called when the output or input stream is closed. It does not do anything
- * on the server side since the operation of the Operation object is not
- * done until after the handler returns from its method.
- * @param inStream <code>true</code> if the input stream is closed;
- * <code>false</code> if the output stream is closed
- * @throws IOException if an IO error occurs
- */
- public void streamClosed(boolean inStream) throws IOException {
-
- }
-
- public void noBodyHeader(){
- mSendBodyHeader = false;
- }
-}
diff --git a/obex/javax/obex/ServerRequestHandler.java b/obex/javax/obex/ServerRequestHandler.java
deleted file mode 100644
index 09cbc2c..0000000
--- a/obex/javax/obex/ServerRequestHandler.java
+++ /dev/null
@@ -1,287 +0,0 @@
-/*
- * Copyright (c) 2008-2009, Motorola, Inc.
- *
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of the Motorola, Inc. nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-package javax.obex;
-
-/**
- * The <code>ServerRequestHandler</code> class defines an event listener that
- * will respond to OBEX requests made to the server.
- * <P>
- * The <code>onConnect()</code>, <code>onSetPath()</code>,
- * <code>onDelete()</code>, <code>onGet()</code>, and <code>onPut()</code>
- * methods may return any response code defined in the
- * <code>ResponseCodes</code> class except for <code>OBEX_HTTP_CONTINUE</code>.
- * If <code>OBEX_HTTP_CONTINUE</code> or a value not defined in the
- * <code>ResponseCodes</code> class is returned, the server implementation will
- * send an <code>OBEX_HTTP_INTERNAL_ERROR</code> response to the client.
- * <P>
- * <STRONG>Connection ID and Target Headers</STRONG>
- * <P>
- * According to the IrOBEX specification, a packet may not contain a Connection
- * ID and Target header. Since the Connection ID header is managed by the
- * implementation, it will not send a Connection ID header, if a Connection ID
- * was specified, in a packet that has a Target header. In other words, if an
- * application adds a Target header to a <code>HeaderSet</code> object used in
- * an OBEX operation and a Connection ID was specified, no Connection ID will be
- * sent in the packet containing the Target header.
- * <P>
- * <STRONG>CREATE-EMPTY Requests</STRONG>
- * <P>
- * A CREATE-EMPTY request allows clients to create empty objects on the server.
- * When a CREATE-EMPTY request is received, the <code>onPut()</code> method will
- * be called by the implementation. To differentiate between a normal PUT
- * request and a CREATE-EMPTY request, an application must open the
- * <code>InputStream</code> from the <code>Operation</code> object passed to the
- * <code>onPut()</code> method. For a PUT request, the application will be able
- * to read Body data from this <code>InputStream</code>. For a CREATE-EMPTY
- * request, there will be no Body data to read. Therefore, a call to
- * <code>InputStream.read()</code> will return -1.
- * @hide
- */
-public class ServerRequestHandler {
-
- private long mConnectionId;
-
- /**
- * Creates a <code>ServerRequestHandler</code>.
- */
- protected ServerRequestHandler() {
- /*
- * A connection ID of -1 implies there is no conenction ID
- */
- mConnectionId = -1;
- }
-
- /**
- * Sets the connection ID header to include in the reply packets.
- * @param connectionId the connection ID to use; -1 if no connection ID
- * should be sent
- * @throws IllegalArgumentException if <code>id</code> is not in the range
- * -1 to 2<sup>32</sup>-1
- */
- public void setConnectionId(final long connectionId) {
- if ((connectionId < -1) || (connectionId > 0xFFFFFFFFL)) {
- throw new IllegalArgumentException("Illegal Connection ID");
- }
- mConnectionId = connectionId;
- }
-
- /**
- * Retrieves the connection ID that is being used in the present connection.
- * This method will return -1 if no connection ID is being used.
- * @return the connection id being used or -1 if no connection ID is being
- * used
- */
- public long getConnectionId() {
- return mConnectionId;
- }
-
- /**
- * Called when a CONNECT request is received.
- * <P>
- * If this method is not implemented by the class that extends this class,
- * <code>onConnect()</code> will always return an <code>OBEX_HTTP_OK</code>
- * response code.
- * <P>
- * The headers received in the request can be retrieved from the
- * <code>request</code> argument. The headers that should be sent in the
- * reply must be specified in the <code>reply</code> argument.
- * @param request contains the headers sent by the client;
- * <code>request</code> will never be <code>null</code>
- * @param reply the headers that should be sent in the reply;
- * <code>reply</code> will never be <code>null</code>
- * @return a response code defined in <code>ResponseCodes</code> that will
- * be returned to the client; if an invalid response code is
- * provided, the <code>OBEX_HTTP_INTERNAL_ERROR</code> response code
- * will be used
- */
- public int onConnect(HeaderSet request, HeaderSet reply) {
- return ResponseCodes.OBEX_HTTP_OK;
- }
-
- /**
- * Called when a DISCONNECT request is received.
- * <P>
- * The headers received in the request can be retrieved from the
- * <code>request</code> argument. The headers that should be sent in the
- * reply must be specified in the <code>reply</code> argument.
- * @param request contains the headers sent by the client;
- * <code>request</code> will never be <code>null</code>
- * @param reply the headers that should be sent in the reply;
- * <code>reply</code> will never be <code>null</code>
- */
- public void onDisconnect(HeaderSet request, HeaderSet reply) {
- }
-
- /**
- * Called when a SETPATH request is received.
- * <P>
- * If this method is not implemented by the class that extends this class,
- * <code>onSetPath()</code> will always return an
- * <code>OBEX_HTTP_NOT_IMPLEMENTED</code> response code.
- * <P>
- * The headers received in the request can be retrieved from the
- * <code>request</code> argument. The headers that should be sent in the
- * reply must be specified in the <code>reply</code> argument.
- * @param request contains the headers sent by the client;
- * <code>request</code> will never be <code>null</code>
- * @param reply the headers that should be sent in the reply;
- * <code>reply</code> will never be <code>null</code>
- * @param backup <code>true</code> if the client requests that the server
- * back up one directory before changing to the path described by
- * <code>name</code>; <code>false</code> to apply the request to the
- * present path
- * @param create <code>true</code> if the path should be created if it does
- * not already exist; <code>false</code> if the path should not be
- * created if it does not exist and an error code should be returned
- * @return a response code defined in <code>ResponseCodes</code> that will
- * be returned to the client; if an invalid response code is
- * provided, the <code>OBEX_HTTP_INTERNAL_ERROR</code> response code
- * will be used
- */
- public int onSetPath(HeaderSet request, HeaderSet reply, boolean backup, boolean create) {
-
- return ResponseCodes.OBEX_HTTP_NOT_IMPLEMENTED;
- }
-
- /**
- * Called when a DELETE request is received.
- * <P>
- * If this method is not implemented by the class that extends this class,
- * <code>onDelete()</code> will always return an
- * <code>OBEX_HTTP_NOT_IMPLEMENTED</code> response code.
- * <P>
- * The headers received in the request can be retrieved from the
- * <code>request</code> argument. The headers that should be sent in the
- * reply must be specified in the <code>reply</code> argument.
- * @param request contains the headers sent by the client;
- * <code>request</code> will never be <code>null</code>
- * @param reply the headers that should be sent in the reply;
- * <code>reply</code> will never be <code>null</code>
- * @return a response code defined in <code>ResponseCodes</code> that will
- * be returned to the client; if an invalid response code is
- * provided, the <code>OBEX_HTTP_INTERNAL_ERROR</code> response code
- * will be used
- */
- public int onDelete(HeaderSet request, HeaderSet reply) {
- return ResponseCodes.OBEX_HTTP_NOT_IMPLEMENTED;
- }
-
- /**
- * Called when a ABORT request is received.
- */
- public int onAbort(HeaderSet request, HeaderSet reply) {
- return ResponseCodes.OBEX_HTTP_NOT_IMPLEMENTED;
- }
-
- /**
- * Called when a PUT request is received.
- * <P>
- * If this method is not implemented by the class that extends this class,
- * <code>onPut()</code> will always return an
- * <code>OBEX_HTTP_NOT_IMPLEMENTED</code> response code.
- * <P>
- * If an ABORT request is received during the processing of a PUT request,
- * <code>op</code> will be closed by the implementation.
- * @param operation contains the headers sent by the client and allows new
- * headers to be sent in the reply; <code>op</code> will never be
- * <code>null</code>
- * @return a response code defined in <code>ResponseCodes</code> that will
- * be returned to the client; if an invalid response code is
- * provided, the <code>OBEX_HTTP_INTERNAL_ERROR</code> response code
- * will be used
- */
- public int onPut(Operation operation) {
- return ResponseCodes.OBEX_HTTP_NOT_IMPLEMENTED;
- }
-
- /**
- * Called when a GET request is received.
- * <P>
- * If this method is not implemented by the class that extends this class,
- * <code>onGet()</code> will always return an
- * <code>OBEX_HTTP_NOT_IMPLEMENTED</code> response code.
- * <P>
- * If an ABORT request is received during the processing of a GET request,
- * <code>op</code> will be closed by the implementation.
- * @param operation contains the headers sent by the client and allows new
- * headers to be sent in the reply; <code>op</code> will never be
- * <code>null</code>
- * @return a response code defined in <code>ResponseCodes</code> that will
- * be returned to the client; if an invalid response code is
- * provided, the <code>OBEX_HTTP_INTERNAL_ERROR</code> response code
- * will be used
- */
- public int onGet(Operation operation) {
- return ResponseCodes.OBEX_HTTP_NOT_IMPLEMENTED;
- }
-
- /**
- * Called when this object attempts to authenticate a client and the
- * authentication request fails because the response digest in the
- * authentication response header was wrong.
- * <P>
- * If this method is not implemented by the class that extends this class,
- * this method will do nothing.
- * @param userName the user name returned in the authentication response;
- * <code>null</code> if no user name was provided in the response
- */
- public void onAuthenticationFailure(byte[] userName) {
- }
-
- /**
- * Called by ServerSession to update the status of current transaction
- * <P>
- * If this method is not implemented by the class that extends this class,
- * this method will do nothing.
- */
- public void updateStatus(String message) {
- }
-
- /**
- * Called when session is closed.
- * <P>
- * If this method is not implemented by the class that extends this class,
- * this method will do nothing.
- */
- public void onClose() {
- }
-
- /**
- * Override to add Single Response Mode support - e.g. if the supplied
- * transport is l2cap.
- * @return True if SRM is supported, else False
- */
- public boolean isSrmSupported() {
- return false;
- }
-}
diff --git a/obex/javax/obex/ServerSession.java b/obex/javax/obex/ServerSession.java
deleted file mode 100644
index dbfeefd..0000000
--- a/obex/javax/obex/ServerSession.java
+++ /dev/null
@@ -1,742 +0,0 @@
-/*
- * Copyright (C) 2015 The Android Open Source Project
- * Copyright (c) 2015 Samsung LSI
- * Copyright (c) 2008-2009, Motorola, Inc.
- *
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of the Motorola, Inc. nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-package javax.obex;
-
-import android.util.Log;
-
-import java.io.InputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-
-/**
- * This class in an implementation of the OBEX ServerSession.
- * @hide
- */
-public final class ServerSession extends ObexSession implements Runnable {
-
- private static final String TAG = "Obex ServerSession";
- private static final boolean V = ObexHelper.VDBG;
-
- private ObexTransport mTransport;
-
- private InputStream mInput;
-
- private OutputStream mOutput;
-
- private ServerRequestHandler mListener;
-
- private Thread mProcessThread;
-
- private int mMaxPacketLength;
-
- private boolean mClosed;
-
- /**
- * Creates new ServerSession.
- * @param trans the connection to the client
- * @param handler the event listener that will process requests
- * @param auth the authenticator to use with this connection
- * @throws IOException if an error occurred while opening the input and
- * output streams
- */
- public ServerSession(ObexTransport trans, ServerRequestHandler handler, Authenticator auth)
- throws IOException {
- mAuthenticator = auth;
- mTransport = trans;
- mInput = mTransport.openInputStream();
- mOutput = mTransport.openOutputStream();
- mListener = handler;
- mMaxPacketLength = 256;
-
- mClosed = false;
- mProcessThread = new Thread(this);
- mProcessThread.start();
- }
-
- /**
- * Processes requests made to the server and forwards them to the
- * appropriate event listener.
- */
- public void run() {
- try {
-
- boolean done = false;
- while (!done && !mClosed) {
- if(V) Log.v(TAG, "Waiting for incoming request...");
- int requestType = mInput.read();
- if(V) Log.v(TAG, "Read request: " + requestType);
- switch (requestType) {
- case ObexHelper.OBEX_OPCODE_CONNECT:
- handleConnectRequest();
- break;
-
- case ObexHelper.OBEX_OPCODE_DISCONNECT:
- handleDisconnectRequest();
- break;
-
- case ObexHelper.OBEX_OPCODE_GET:
- case ObexHelper.OBEX_OPCODE_GET_FINAL:
- handleGetRequest(requestType);
- break;
-
- case ObexHelper.OBEX_OPCODE_PUT:
- case ObexHelper.OBEX_OPCODE_PUT_FINAL:
- handlePutRequest(requestType);
- break;
-
- case ObexHelper.OBEX_OPCODE_SETPATH:
- handleSetPathRequest();
- break;
- case ObexHelper.OBEX_OPCODE_ABORT:
- handleAbortRequest();
- break;
-
- case -1:
- done = true;
- break;
-
- default:
-
- /*
- * Received a request type that is not recognized so I am
- * just going to read the packet and send a not implemented
- * to the client
- */
- int length = mInput.read();
- length = (length << 8) + mInput.read();
- for (int i = 3; i < length; i++) {
- mInput.read();
- }
- sendResponse(ResponseCodes.OBEX_HTTP_NOT_IMPLEMENTED, null);
- }
- }
-
- } catch (NullPointerException e) {
- Log.d(TAG, "Exception occured - ignoring", e);
- } catch (Exception e) {
- Log.d(TAG, "Exception occured - ignoring", e);
- }
- close();
- }
-
- /**
- * Handles a ABORT request from a client. This method will read the rest of
- * the request from the client. Assuming the request is valid, it will
- * create a <code>HeaderSet</code> object to pass to the
- * <code>ServerRequestHandler</code> object. After the handler processes the
- * request, this method will create a reply message to send to the server.
- *
- * @throws IOException if an error occurred at the transport layer
- */
- private void handleAbortRequest() throws IOException {
- int code = ResponseCodes.OBEX_HTTP_OK;
- HeaderSet request = new HeaderSet();
- HeaderSet reply = new HeaderSet();
-
- int length = mInput.read();
- length = (length << 8) + mInput.read();
- if (length > ObexHelper.getMaxRxPacketSize(mTransport)) {
- code = ResponseCodes.OBEX_HTTP_REQ_TOO_LARGE;
- } else {
- for (int i = 3; i < length; i++) {
- mInput.read();
- }
- code = mListener.onAbort(request, reply);
- Log.v(TAG, "onAbort request handler return value- " + code);
- code = validateResponseCode(code);
- }
- sendResponse(code, null);
- }
-
- /**
- * Handles a PUT request from a client. This method will provide a
- * <code>ServerOperation</code> object to the request handler. The
- * <code>ServerOperation</code> object will handle the rest of the request.
- * It will also send replies and receive requests until the final reply
- * should be sent. When the final reply should be sent, this method will get
- * the response code to use and send the reply. The
- * <code>ServerOperation</code> object will always reply with a
- * OBEX_HTTP_CONTINUE reply. It will only reply if further information is
- * needed.
- * @param type the type of request received; either 0x02 or 0x82
- * @throws IOException if an error occurred at the transport layer
- */
- private void handlePutRequest(int type) throws IOException {
- ServerOperation op = new ServerOperation(this, mInput, type, mMaxPacketLength, mListener);
- try {
- int response = -1;
-
- if ((op.finalBitSet) && !op.isValidBody()) {
- response = validateResponseCode(mListener
- .onDelete(op.requestHeader, op.replyHeader));
- } else {
- response = validateResponseCode(mListener.onPut(op));
- }
- if (response != ResponseCodes.OBEX_HTTP_OK && !op.isAborted) {
- op.sendReply(response);
- } else if (!op.isAborted) {
- // wait for the final bit
- while (!op.finalBitSet) {
- op.sendReply(ResponseCodes.OBEX_HTTP_CONTINUE);
- }
- op.sendReply(response);
- }
- } catch (Exception e) {
- /*To fix bugs in aborted cases,
- *(client abort file transfer prior to the last packet which has the end of body header,
- *internal error should not be sent because server has already replied with
- *OK response in "sendReply")
- */
- if(V) Log.d(TAG,"Exception occured - sending OBEX_HTTP_INTERNAL_ERROR reply",e);
- if (!op.isAborted) {
- sendResponse(ResponseCodes.OBEX_HTTP_INTERNAL_ERROR, null);
- }
- }
- }
-
- /**
- * Handles a GET request from a client. This method will provide a
- * <code>ServerOperation</code> object to the request handler. The
- * <code>ServerOperation</code> object will handle the rest of the request.
- * It will also send replies and receive requests until the final reply
- * should be sent. When the final reply should be sent, this method will get
- * the response code to use and send the reply. The
- * <code>ServerOperation</code> object will always reply with a
- * OBEX_HTTP_CONTINUE reply. It will only reply if further information is
- * needed.
- * @param type the type of request received; either 0x03 or 0x83
- * @throws IOException if an error occurred at the transport layer
- */
- private void handleGetRequest(int type) throws IOException {
- ServerOperation op = new ServerOperation(this, mInput, type, mMaxPacketLength, mListener);
- try {
- int response = validateResponseCode(mListener.onGet(op));
-
- if (!op.isAborted) {
- op.sendReply(response);
- }
- } catch (Exception e) {
- if(V) Log.d(TAG,"Exception occured - sending OBEX_HTTP_INTERNAL_ERROR reply",e);
- sendResponse(ResponseCodes.OBEX_HTTP_INTERNAL_ERROR, null);
- }
- }
-
- /**
- * Send standard response.
- * @param code the response code to send
- * @param header the headers to include in the response
- * @throws IOException if an IO error occurs
- */
- public void sendResponse(int code, byte[] header) throws IOException {
- int totalLength = 3;
- byte[] data = null;
- OutputStream op = mOutput;
- if (op == null) {
- return;
- }
-
- if (header != null) {
- totalLength += header.length;
- data = new byte[totalLength];
- data[0] = (byte)code;
- data[1] = (byte)(totalLength >> 8);
- data[2] = (byte)totalLength;
- System.arraycopy(header, 0, data, 3, header.length);
- } else {
- data = new byte[totalLength];
- data[0] = (byte)code;
- data[1] = (byte)0x00;
- data[2] = (byte)totalLength;
- }
- op.write(data);
- op.flush(); // TODO: Do we need to flush?
- }
-
- /**
- * Handles a SETPATH request from a client. This method will read the rest
- * of the request from the client. Assuming the request is valid, it will
- * create a <code>HeaderSet</code> object to pass to the
- * <code>ServerRequestHandler</code> object. After the handler processes the
- * request, this method will create a reply message to send to the server
- * with the response code provided.
- * @throws IOException if an error occurred at the transport layer
- */
- private void handleSetPathRequest() throws IOException {
- int length;
- int flags;
- @SuppressWarnings("unused")
- int constants;
- int totalLength = 3;
- byte[] head = null;
- int code = -1;
- int bytesReceived;
- HeaderSet request = new HeaderSet();
- HeaderSet reply = new HeaderSet();
-
- length = mInput.read();
- length = (length << 8) + mInput.read();
- flags = mInput.read();
- constants = mInput.read();
-
- if (length > ObexHelper.getMaxRxPacketSize(mTransport)) {
- code = ResponseCodes.OBEX_HTTP_REQ_TOO_LARGE;
- totalLength = 3;
- } else {
- if (length > 5) {
- byte[] headers = new byte[length - 5];
- bytesReceived = mInput.read(headers);
-
- while (bytesReceived != headers.length) {
- bytesReceived += mInput.read(headers, bytesReceived, headers.length
- - bytesReceived);
- }
-
- ObexHelper.updateHeaderSet(request, headers);
-
- if (mListener.getConnectionId() != -1 && request.mConnectionID != null) {
- mListener.setConnectionId(ObexHelper.convertToLong(request.mConnectionID));
- } else {
- mListener.setConnectionId(1);
- }
- // the Auth chan is initiated by the server, client sent back the authResp .
- if (request.mAuthResp != null) {
- if (!handleAuthResp(request.mAuthResp)) {
- code = ResponseCodes.OBEX_HTTP_UNAUTHORIZED;
- mListener.onAuthenticationFailure(ObexHelper.getTagValue((byte)0x01,
- request.mAuthResp));
- }
- request.mAuthResp = null;
- }
- }
-
- if (code != ResponseCodes.OBEX_HTTP_UNAUTHORIZED) {
- // the Auth challenge is initiated by the client
- // the server will send back the authResp to the client
- if (request.mAuthChall != null) {
- handleAuthChall(request);
- reply.mAuthResp = new byte[request.mAuthResp.length];
- System.arraycopy(request.mAuthResp, 0, reply.mAuthResp, 0,
- reply.mAuthResp.length);
- request.mAuthChall = null;
- request.mAuthResp = null;
- }
- boolean backup = false;
- boolean create = true;
- if (!((flags & 1) == 0)) {
- backup = true;
- }
- if (!((flags & 2) == 0)) {
- create = false;
- }
-
- try {
- code = mListener.onSetPath(request, reply, backup, create);
- } catch (Exception e) {
- if(V) Log.d(TAG,"Exception occured - sending OBEX_HTTP_INTERNAL_ERROR reply",e);
- sendResponse(ResponseCodes.OBEX_HTTP_INTERNAL_ERROR, null);
- return;
- }
-
- code = validateResponseCode(code);
-
- if (reply.nonce != null) {
- mChallengeDigest = new byte[16];
- System.arraycopy(reply.nonce, 0, mChallengeDigest, 0, 16);
- } else {
- mChallengeDigest = null;
- }
-
- long id = mListener.getConnectionId();
- if (id == -1) {
- reply.mConnectionID = null;
- } else {
- reply.mConnectionID = ObexHelper.convertToByteArray(id);
- }
-
- head = ObexHelper.createHeader(reply, false);
- totalLength += head.length;
-
- if (totalLength > mMaxPacketLength) {
- totalLength = 3;
- head = null;
- code = ResponseCodes.OBEX_HTTP_INTERNAL_ERROR;
- }
- }
- }
-
- // Compute Length of OBEX SETPATH packet
- byte[] replyData = new byte[totalLength];
- replyData[0] = (byte)code;
- replyData[1] = (byte)(totalLength >> 8);
- replyData[2] = (byte)totalLength;
- if (head != null) {
- System.arraycopy(head, 0, replyData, 3, head.length);
- }
- /*
- * Write the OBEX SETPATH packet to the server. Byte 0: response code
- * Byte 1&2: Connect Packet Length Byte 3 to n: headers
- */
- mOutput.write(replyData);
- mOutput.flush();
- }
-
- /**
- * Handles a disconnect request from a client. This method will read the
- * rest of the request from the client. Assuming the request is valid, it
- * will create a <code>HeaderSet</code> object to pass to the
- * <code>ServerRequestHandler</code> object. After the handler processes the
- * request, this method will create a reply message to send to the server.
- * @throws IOException if an error occurred at the transport layer
- */
- private void handleDisconnectRequest() throws IOException {
- int length;
- int code = ResponseCodes.OBEX_HTTP_OK;
- int totalLength = 3;
- byte[] head = null;
- int bytesReceived;
- HeaderSet request = new HeaderSet();
- HeaderSet reply = new HeaderSet();
-
- length = mInput.read();
- length = (length << 8) + mInput.read();
-
- if (length > ObexHelper.getMaxRxPacketSize(mTransport)) {
- code = ResponseCodes.OBEX_HTTP_REQ_TOO_LARGE;
- totalLength = 3;
- } else {
- if (length > 3) {
- byte[] headers = new byte[length - 3];
- bytesReceived = mInput.read(headers);
-
- while (bytesReceived != headers.length) {
- bytesReceived += mInput.read(headers, bytesReceived, headers.length
- - bytesReceived);
- }
-
- ObexHelper.updateHeaderSet(request, headers);
- }
-
- if (mListener.getConnectionId() != -1 && request.mConnectionID != null) {
- mListener.setConnectionId(ObexHelper.convertToLong(request.mConnectionID));
- } else {
- mListener.setConnectionId(1);
- }
-
- if (request.mAuthResp != null) {
- if (!handleAuthResp(request.mAuthResp)) {
- code = ResponseCodes.OBEX_HTTP_UNAUTHORIZED;
- mListener.onAuthenticationFailure(ObexHelper.getTagValue((byte)0x01,
- request.mAuthResp));
- }
- request.mAuthResp = null;
- }
-
- if (code != ResponseCodes.OBEX_HTTP_UNAUTHORIZED) {
-
- if (request.mAuthChall != null) {
- handleAuthChall(request);
- request.mAuthChall = null;
- }
-
- try {
- mListener.onDisconnect(request, reply);
- } catch (Exception e) {
- if(V) Log.d(TAG,"Exception occured - sending OBEX_HTTP_INTERNAL_ERROR reply",e);
- sendResponse(ResponseCodes.OBEX_HTTP_INTERNAL_ERROR, null);
- return;
- }
-
- long id = mListener.getConnectionId();
- if (id == -1) {
- reply.mConnectionID = null;
- } else {
- reply.mConnectionID = ObexHelper.convertToByteArray(id);
- }
-
- head = ObexHelper.createHeader(reply, false);
- totalLength += head.length;
-
- if (totalLength > mMaxPacketLength) {
- totalLength = 3;
- head = null;
- code = ResponseCodes.OBEX_HTTP_INTERNAL_ERROR;
- }
- }
- }
-
- // Compute Length of OBEX CONNECT packet
- byte[] replyData;
- if (head != null) {
- replyData = new byte[3 + head.length];
- } else {
- replyData = new byte[3];
- }
- replyData[0] = (byte)code;
- replyData[1] = (byte)(totalLength >> 8);
- replyData[2] = (byte)totalLength;
- if (head != null) {
- System.arraycopy(head, 0, replyData, 3, head.length);
- }
- /*
- * Write the OBEX DISCONNECT packet to the server. Byte 0: response code
- * Byte 1&2: Connect Packet Length Byte 3 to n: headers
- */
- mOutput.write(replyData);
- mOutput.flush();
- }
-
- /**
- * Handles a connect request from a client. This method will read the rest
- * of the request from the client. Assuming the request is valid, it will
- * create a <code>HeaderSet</code> object to pass to the
- * <code>ServerRequestHandler</code> object. After the handler processes the
- * request, this method will create a reply message to send to the server
- * with the response code provided.
- * @throws IOException if an error occurred at the transport layer
- */
- private void handleConnectRequest() throws IOException {
- int packetLength;
- @SuppressWarnings("unused")
- int version;
- @SuppressWarnings("unused")
- int flags;
- int totalLength = 7;
- byte[] head = null;
- int code = -1;
- HeaderSet request = new HeaderSet();
- HeaderSet reply = new HeaderSet();
- int bytesReceived;
-
- if(V) Log.v(TAG,"handleConnectRequest()");
-
- /*
- * Read in the length of the OBEX packet, OBEX version, flags, and max
- * packet length
- */
- packetLength = mInput.read();
- packetLength = (packetLength << 8) + mInput.read();
- if(V) Log.v(TAG,"handleConnectRequest() - packetLength: " + packetLength);
-
- version = mInput.read();
- flags = mInput.read();
- mMaxPacketLength = mInput.read();
- mMaxPacketLength = (mMaxPacketLength << 8) + mInput.read();
-
- if(V) Log.v(TAG,"handleConnectRequest() - version: " + version
- + " MaxLength: " + mMaxPacketLength + " flags: " + flags);
-
- // should we check it?
- if (mMaxPacketLength > ObexHelper.MAX_PACKET_SIZE_INT) {
- mMaxPacketLength = ObexHelper.MAX_PACKET_SIZE_INT;
- }
-
- if(mMaxPacketLength > ObexHelper.getMaxTxPacketSize(mTransport)) {
- Log.w(TAG, "Requested MaxObexPacketSize " + mMaxPacketLength
- + " is larger than the max size supported by the transport: "
- + ObexHelper.getMaxTxPacketSize(mTransport)
- + " Reducing to this size.");
- mMaxPacketLength = ObexHelper.getMaxTxPacketSize(mTransport);
- }
-
- if (packetLength > ObexHelper.getMaxRxPacketSize(mTransport)) {
- code = ResponseCodes.OBEX_HTTP_REQ_TOO_LARGE;
- totalLength = 7;
- } else {
- if (packetLength > 7) {
- byte[] headers = new byte[packetLength - 7];
- bytesReceived = mInput.read(headers);
-
- while (bytesReceived != headers.length) {
- bytesReceived += mInput.read(headers, bytesReceived, headers.length
- - bytesReceived);
- }
-
- ObexHelper.updateHeaderSet(request, headers);
- }
-
- if (mListener.getConnectionId() != -1 && request.mConnectionID != null) {
- mListener.setConnectionId(ObexHelper.convertToLong(request.mConnectionID));
- } else {
- mListener.setConnectionId(1);
- }
-
- if (request.mAuthResp != null) {
- if (!handleAuthResp(request.mAuthResp)) {
- code = ResponseCodes.OBEX_HTTP_UNAUTHORIZED;
- mListener.onAuthenticationFailure(ObexHelper.getTagValue((byte)0x01,
- request.mAuthResp));
- }
- request.mAuthResp = null;
- }
-
- if (code != ResponseCodes.OBEX_HTTP_UNAUTHORIZED) {
- if (request.mAuthChall != null) {
- handleAuthChall(request);
- reply.mAuthResp = new byte[request.mAuthResp.length];
- System.arraycopy(request.mAuthResp, 0, reply.mAuthResp, 0,
- reply.mAuthResp.length);
- request.mAuthChall = null;
- request.mAuthResp = null;
- }
-
- try {
- code = mListener.onConnect(request, reply);
- code = validateResponseCode(code);
-
- if (reply.nonce != null) {
- mChallengeDigest = new byte[16];
- System.arraycopy(reply.nonce, 0, mChallengeDigest, 0, 16);
- } else {
- mChallengeDigest = null;
- }
- long id = mListener.getConnectionId();
- if (id == -1) {
- reply.mConnectionID = null;
- } else {
- reply.mConnectionID = ObexHelper.convertToByteArray(id);
- }
-
- head = ObexHelper.createHeader(reply, false);
- totalLength += head.length;
-
- if (totalLength > mMaxPacketLength) {
- totalLength = 7;
- head = null;
- code = ResponseCodes.OBEX_HTTP_INTERNAL_ERROR;
- }
- } catch (Exception e) {
- if(V) Log.d(TAG,"Exception occured - sending OBEX_HTTP_INTERNAL_ERROR reply",e);
- totalLength = 7;
- head = null;
- code = ResponseCodes.OBEX_HTTP_INTERNAL_ERROR;
- }
-
- }
- }
-
- // Compute Length of OBEX CONNECT packet
- byte[] length = ObexHelper.convertToByteArray(totalLength);
-
- /*
- * Write the OBEX CONNECT packet to the server. Byte 0: response code
- * Byte 1&2: Connect Packet Length Byte 3: OBEX Version Number
- * (Presently, 0x10) Byte 4: Flags (For TCP 0x00) Byte 5&6: Max OBEX
- * Packet Length (Defined in MAX_PACKET_SIZE) Byte 7 to n: headers
- */
- byte[] sendData = new byte[totalLength];
- int maxRxLength = ObexHelper.getMaxRxPacketSize(mTransport);
- if (maxRxLength > mMaxPacketLength) {
- if(V) Log.v(TAG,"Set maxRxLength to min of maxRxServrLen:" + maxRxLength +
- " and MaxNegotiated from Client: " + mMaxPacketLength);
- maxRxLength = mMaxPacketLength;
- }
- sendData[0] = (byte)code;
- sendData[1] = length[2];
- sendData[2] = length[3];
- sendData[3] = (byte)0x10;
- sendData[4] = (byte)0x00;
- sendData[5] = (byte)(maxRxLength >> 8);
- sendData[6] = (byte)(maxRxLength & 0xFF);
-
- if (head != null) {
- System.arraycopy(head, 0, sendData, 7, head.length);
- }
-
- mOutput.write(sendData);
- mOutput.flush();
- }
-
- /**
- * Closes the server session - in detail close I/O streams and the
- * underlying transport layer. Internal flag is also set so that later
- * attempt to read/write will throw an exception.
- */
- public synchronized void close() {
- if (mListener != null) {
- mListener.onClose();
- }
- try {
- /* Set state to closed before interrupting the thread by closing the streams */
- mClosed = true;
- if(mInput != null)
- mInput.close();
- if(mOutput != null)
- mOutput.close();
- if(mTransport != null)
- mTransport.close();
- } catch (Exception e) {
- if(V) Log.d(TAG,"Exception occured during close() - ignore",e);
- }
- mTransport = null;
- mInput = null;
- mOutput = null;
- mListener = null;
- }
-
- /**
- * Verifies that the response code is valid. If it is not valid, it will
- * return the <code>OBEX_HTTP_INTERNAL_ERROR</code> response code.
- * @param code the response code to check
- * @return the valid response code or <code>OBEX_HTTP_INTERNAL_ERROR</code>
- * if <code>code</code> is not valid
- */
- private int validateResponseCode(int code) {
-
- if ((code >= ResponseCodes.OBEX_HTTP_OK) && (code <= ResponseCodes.OBEX_HTTP_PARTIAL)) {
- return code;
- }
- if ((code >= ResponseCodes.OBEX_HTTP_MULT_CHOICE)
- && (code <= ResponseCodes.OBEX_HTTP_USE_PROXY)) {
- return code;
- }
- if ((code >= ResponseCodes.OBEX_HTTP_BAD_REQUEST)
- && (code <= ResponseCodes.OBEX_HTTP_UNSUPPORTED_TYPE)) {
- return code;
- }
- if ((code >= ResponseCodes.OBEX_HTTP_INTERNAL_ERROR)
- && (code <= ResponseCodes.OBEX_HTTP_VERSION)) {
- return code;
- }
- if ((code >= ResponseCodes.OBEX_DATABASE_FULL)
- && (code <= ResponseCodes.OBEX_DATABASE_LOCKED)) {
- return code;
- }
- return ResponseCodes.OBEX_HTTP_INTERNAL_ERROR;
- }
-
- public ObexTransport getTransport() {
- return mTransport;
- }
-}
diff --git a/obex/javax/obex/SessionNotifier.java b/obex/javax/obex/SessionNotifier.java
deleted file mode 100644
index 9836dd6..0000000
--- a/obex/javax/obex/SessionNotifier.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * Copyright (c) 2008-2009, Motorola, Inc.
- *
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of the Motorola, Inc. nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-package javax.obex;
-
-import java.io.IOException;
-
-/**
- * The <code>SessionNotifier</code> interface defines a connection notifier for
- * server-side OBEX connections. When a <code>SessionNotifier</code> is created
- * and calls <code>acceptAndOpen()</code>, it will begin listening for clients
- * to create a connection at the transport layer. When the transport layer
- * connection is received, the <code>acceptAndOpen()</code> method will return a
- * <code>javax.microedition.io.Connection</code> that is the connection to the
- * client. The <code>acceptAndOpen()</code> method also takes a
- * <code>ServerRequestHandler</code> argument that will process the requests
- * from the client that connects to the server.
- * @hide
- */
-public interface SessionNotifier {
-
- /**
- * Waits for a transport layer connection to be established and specifies
- * the handler to handle the requests from the client. No authenticator is
- * associated with this connection, therefore, it is implementation
- * dependent as to how an authentication challenge and authentication
- * response header will be received and processed.
- * <P>
- * <H4>Additional Note for OBEX over Bluetooth</H4> If this method is called
- * on a <code>SessionNotifier</code> object that does not have a
- * <code>ServiceRecord</code> in the SDDB, the <code>ServiceRecord</code>
- * for this object will be added to the SDDB. This method requests the BCC
- * to put the local device in connectable mode so that it will respond to
- * connection attempts by clients.
- * <P>
- * The following checks are done to verify that the service record provided
- * is valid. If any of these checks fail, then a
- * <code>ServiceRegistrationException</code> is thrown.
- * <UL>
- * <LI>ServiceClassIDList and ProtocolDescriptorList, the mandatory service
- * attributes for a <code>btgoep</code> service record, must be present in
- * the <code>ServiceRecord</code> associated with this notifier.
- * <LI>L2CAP, RFCOMM and OBEX must all be in the ProtocolDescriptorList
- * <LI>The <code>ServiceRecord</code> associated with this notifier must not
- * have changed the RFCOMM server channel number
- * </UL>
- * <P>
- * This method will not ensure that <code>ServiceRecord</code> associated
- * with this notifier is a completely valid service record. It is the
- * responsibility of the application to ensure that the service record
- * follows all of the applicable syntactic and semantic rules for service
- * record correctness.
- * @param handler the request handler that will respond to OBEX requests
- * @return the connection to the client
- * @throws IOException if an error occurs in the transport layer
- * @throws NullPointerException if <code>handler</code> is <code>null</code>
- */
- ObexSession acceptAndOpen(ServerRequestHandler handler) throws IOException;
-
- /**
- * Waits for a transport layer connection to be established and specifies
- * the handler to handle the requests from the client and the
- * <code>Authenticator</code> to use to respond to authentication challenge
- * and authentication response headers.
- * <P>
- * <H4>Additional Note for OBEX over Bluetooth</H4> If this method is called
- * on a <code>SessionNotifier</code> object that does not have a
- * <code>ServiceRecord</code> in the SDDB, the <code>ServiceRecord</code>
- * for this object will be added to the SDDB. This method requests the BCC
- * to put the local device in connectable mode so that it will respond to
- * connection attempts by clients.
- * <P>
- * The following checks are done to verify that the service record provided
- * is valid. If any of these checks fail, then a
- * <code>ServiceRegistrationException</code> is thrown.
- * <UL>
- * <LI>ServiceClassIDList and ProtocolDescriptorList, the mandatory service
- * attributes for a <code>btgoep</code> service record, must be present in
- * the <code>ServiceRecord</code> associated with this notifier.
- * <LI>L2CAP, RFCOMM and OBEX must all be in the ProtocolDescriptorList
- * <LI>The <code>ServiceRecord</code> associated with this notifier must not
- * have changed the RFCOMM server channel number
- * </UL>
- * <P>
- * This method will not ensure that <code>ServiceRecord</code> associated
- * with this notifier is a completely valid service record. It is the
- * responsibility of the application to ensure that the service record
- * follows all of the applicable syntactic and semantic rules for service
- * record correctness.
- * @param handler the request handler that will respond to OBEX requests
- * @param auth the <code>Authenticator</code> to use with this connection;
- * if <code>null</code> then no <code>Authenticator</code> will be
- * used
- * @return the connection to the client
- * @throws IOException if an error occurs in the transport layer
- * @throws NullPointerException if <code>handler</code> is <code>null</code>
- */
- ObexSession acceptAndOpen(ServerRequestHandler handler, Authenticator auth) throws IOException;
-}
diff --git a/packages/CompanionDeviceManager/res/color/selector.xml b/packages/CompanionDeviceManager/res/color/selector.xml
index fda827d..56e5dca 100644
--- a/packages/CompanionDeviceManager/res/color/selector.xml
+++ b/packages/CompanionDeviceManager/res/color/selector.xml
@@ -16,5 +16,5 @@
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:color="@android:color/darker_gray"/> <!-- pressed -->
- <item android:color="@android:color/white"/>
+ <item android:color="?android:attr/colorBackground"/>
</selector>
\ No newline at end of file
diff --git a/packages/CompanionDeviceManager/res/drawable/dialog_background.xml b/packages/CompanionDeviceManager/res/drawable/dialog_background.xml
index ef7052d..a017f41 100644
--- a/packages/CompanionDeviceManager/res/drawable/dialog_background.xml
+++ b/packages/CompanionDeviceManager/res/drawable/dialog_background.xml
@@ -16,7 +16,7 @@
<inset xmlns:android="http://schemas.android.com/apk/res/android">
<shape android:shape="rectangle">
- <corners android:radius="@*android:dimen/config_dialogCornerRadius" />
+ <corners android:radius="?android:attr/dialogCornerRadius" />
<solid android:color="?android:attr/colorBackground" />
</shape>
</inset>
diff --git a/packages/CompanionDeviceManager/res/values/themes.xml b/packages/CompanionDeviceManager/res/values/themes.xml
index 8559ef6..7240432 100644
--- a/packages/CompanionDeviceManager/res/values/themes.xml
+++ b/packages/CompanionDeviceManager/res/values/themes.xml
@@ -17,9 +17,7 @@
<resources>
<style name="ChooserActivity"
- parent="@style/Theme.AppCompat.Light.Dialog">
- <item name="windowActionBar">false</item>
- <item name="windowNoTitle">true</item>
+ parent="@android:style/Theme.DeviceDefault.Light.Dialog">
<item name="*android:windowFixedHeightMajor">100%</item>
<item name="*android:windowFixedHeightMinor">100%</item>
<item name="android:windowBackground">@android:color/transparent</item>
diff --git a/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/CompanionDeviceActivity.java b/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/CompanionDeviceActivity.java
index a6a8fcf..ae0c8cc 100644
--- a/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/CompanionDeviceActivity.java
+++ b/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/CompanionDeviceActivity.java
@@ -49,7 +49,7 @@
import android.widget.Button;
import android.widget.TextView;
-import androidx.appcompat.app.AppCompatActivity;
+import androidx.fragment.app.FragmentActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
@@ -59,7 +59,7 @@
* A CompanionDevice activity response for showing the available
* nearby devices to be associated with.
*/
-public class CompanionDeviceActivity extends AppCompatActivity {
+public class CompanionDeviceActivity extends FragmentActivity {
private static final boolean DEBUG = false;
private static final String TAG = CompanionDeviceActivity.class.getSimpleName();
diff --git a/packages/SettingsLib/Android.bp b/packages/SettingsLib/Android.bp
index 7a5ea47..1b7298a 100644
--- a/packages/SettingsLib/Android.bp
+++ b/packages/SettingsLib/Android.bp
@@ -19,6 +19,7 @@
"androidx.appcompat_appcompat",
"androidx.lifecycle_lifecycle-runtime",
"androidx.mediarouter_mediarouter-nodeps",
+ "com.google.android.material_material",
"iconloader",
"WifiTrackerLibRes",
diff --git a/packages/SettingsLib/SettingsTheme/res/values-night-v31/colors.xml b/packages/SettingsLib/SettingsTheme/res/values-night-v31/colors.xml
index 77c4533..5e3907c 100644
--- a/packages/SettingsLib/SettingsTheme/res/values-night-v31/colors.xml
+++ b/packages/SettingsLib/SettingsTheme/res/values-night-v31/colors.xml
@@ -31,7 +31,7 @@
<!-- Dialog accent color -->
<color name="settingslib_dialog_accent">@android:color/system_accent1_100</color>
<!-- Dialog background color. -->
- <color name="settingslib_dialog_background">@android:color/system_neutral1_800</color>
+ <color name="settingslib_dialog_background">@color/settingslib_surface_dark</color>
<!-- Dialog error color. -->
<color name="settingslib_dialog_colorError">#f28b82</color> <!-- Red 300 -->
@@ -49,4 +49,8 @@
<color name="settingslib_text_color_preference_category_title">@android:color/system_accent1_100</color>
<color name="settingslib_ripple_color">@color/settingslib_material_grey_900</color>
+
+ <color name="settingslib_surface_dark">@android:color/system_neutral1_800</color>
+
+ <color name="settingslib_colorSurface">@color/settingslib_surface_dark</color>
</resources>
\ No newline at end of file
diff --git a/packages/SettingsLib/SettingsTheme/res/values-v31/colors.xml b/packages/SettingsLib/SettingsTheme/res/values-v31/colors.xml
index 6adb789..c4dbc5e 100644
--- a/packages/SettingsLib/SettingsTheme/res/values-v31/colors.xml
+++ b/packages/SettingsLib/SettingsTheme/res/values-v31/colors.xml
@@ -71,5 +71,12 @@
<color name="settingslib_text_color_preference_category_title">@android:color/system_accent1_600</color>
<color name="settingslib_ripple_color">?android:attr/colorControlHighlight</color>
+
<color name="settingslib_material_grey_900">#ff212121</color>
+
+ <color name="settingslib_colorAccentPrimary">@color/settingslib_accent_primary_device_default</color>
+
+ <color name="settingslib_colorAccentSecondary">@color/settingslib_accent_secondary_device_default</color>
+
+ <color name="settingslib_colorSurface">@color/settingslib_surface_light</color>
</resources>
diff --git a/packages/SettingsLib/res/color-night-v31/settingslib_tabs_indicator_color.xml b/packages/SettingsLib/res/color-night-v31/settingslib_tabs_indicator_color.xml
new file mode 100644
index 0000000..9a09360
--- /dev/null
+++ b/packages/SettingsLib/res/color-night-v31/settingslib_tabs_indicator_color.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2022 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.
+-->
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:color="@color/settingslib_colorAccentSecondary" />
+</selector>
\ No newline at end of file
diff --git a/packages/SettingsLib/res/color-night-v31/settingslib_tabs_text_color.xml b/packages/SettingsLib/res/color-night-v31/settingslib_tabs_text_color.xml
new file mode 100644
index 0000000..33f96df
--- /dev/null
+++ b/packages/SettingsLib/res/color-night-v31/settingslib_tabs_text_color.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2022 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.
+-->
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:state_selected="true" android:color="?android:attr/textColorPrimaryInverse"/>
+ <item android:state_enabled="false" android:color="?android:attr/textColorTertiary"/>
+ <item android:color="?android:attr/textColorSecondary"/>
+</selector>
\ No newline at end of file
diff --git a/packages/SettingsLib/res/color-v31/settingslib_tabs_indicator_color.xml b/packages/SettingsLib/res/color-v31/settingslib_tabs_indicator_color.xml
new file mode 100644
index 0000000..57fef52f
--- /dev/null
+++ b/packages/SettingsLib/res/color-v31/settingslib_tabs_indicator_color.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2022 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.
+-->
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:color="@color/settingslib_colorAccentPrimary" />
+</selector>
\ No newline at end of file
diff --git a/packages/SettingsLib/res/color-v31/settingslib_tabs_text_color.xml b/packages/SettingsLib/res/color-v31/settingslib_tabs_text_color.xml
new file mode 100644
index 0000000..df2346d
--- /dev/null
+++ b/packages/SettingsLib/res/color-v31/settingslib_tabs_text_color.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2022 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.
+-->
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:state_selected="true" android:color="?android:attr/textColorPrimary"/>
+ <item android:state_enabled="false" android:color="?android:attr/textColorTertiary"/>
+ <item android:color="?android:attr/textColorSecondary"/>
+</selector>
\ No newline at end of file
diff --git a/packages/SettingsLib/res/drawable-v31/settingslib_tabs_background.xml b/packages/SettingsLib/res/drawable-v31/settingslib_tabs_background.xml
new file mode 100644
index 0000000..f10b563
--- /dev/null
+++ b/packages/SettingsLib/res/drawable-v31/settingslib_tabs_background.xml
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2022 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.
+-->
+<ripple xmlns:android="http://schemas.android.com/apk/res/android"
+ android:color="?android:colorControlHighlight">
+ <item android:id="@android:id/mask">
+ <inset
+ android:insetLeft="4dp"
+ android:insetRight="4dp">
+ <shape android:shape="rectangle">
+ <corners android:radius="12dp" />
+ <solid android:color="?android:colorControlHighlight" />
+ </shape>
+ </inset>
+ </item>
+
+ <item android:id="@android:id/background">
+ <inset
+ android:insetLeft="4dp"
+ android:insetRight="4dp">
+ <shape android:shape="rectangle">
+ <solid android:color="@color/settingslib_colorSurface" />
+ <corners android:radius="12dp" />
+ </shape>
+ </inset>
+ </item>
+</ripple>
diff --git a/packages/SettingsLib/res/drawable-v31/settingslib_tabs_indicator_background.xml b/packages/SettingsLib/res/drawable-v31/settingslib_tabs_indicator_background.xml
new file mode 100644
index 0000000..f5a9782
--- /dev/null
+++ b/packages/SettingsLib/res/drawable-v31/settingslib_tabs_indicator_background.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2022 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.
+-->
+<inset xmlns:android="http://schemas.android.com/apk/res/android"
+ android:insetLeft="4dp"
+ android:insetRight="4dp">
+ <shape android:shape="rectangle">
+ <solid android:color="@color/settingslib_tabs_indicator_color" />
+ <corners android:radius="12dp" />
+ </shape>
+</inset>
\ No newline at end of file
diff --git a/packages/SettingsLib/res/values-v31/styles.xml b/packages/SettingsLib/res/values-v31/styles.xml
new file mode 100644
index 0000000..343de2c
--- /dev/null
+++ b/packages/SettingsLib/res/values-v31/styles.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2022 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.
+ -->
+<resources>
+ <style name="SettingsLibTabsTextAppearance" parent="@android:style/TextAppearance.DeviceDefault.Widget.ActionBar.Title">
+ <item name="android:textSize">16sp</item>
+ </style>
+
+ <style name="SettingsLibTabsStyle" parent="Base.Widget.Design.TabLayout">
+ <item name="android:background">@android:color/transparent</item>
+ <item name="android:layout_width">match_parent</item>
+ <item name="android:layout_height">48dp</item>
+ <item name="android:layout_marginStart">?android:attr/listPreferredItemPaddingStart</item>
+ <item name="android:layout_marginEnd">?android:attr/listPreferredItemPaddingEnd</item>
+ <item name="tabGravity">fill</item>
+ <item name="tabBackground">@drawable/settingslib_tabs_background</item>
+ <item name="tabIndicator">@drawable/settingslib_tabs_indicator_background</item>
+ <item name="tabIndicatorColor">@color/settingslib_tabs_indicator_color</item>
+ <item name="tabIndicatorFullWidth">true</item>
+ <item name="tabIndicatorGravity">stretch</item>
+ <item name="tabIndicatorAnimationMode">fade</item>
+ <item name="tabIndicatorAnimationDuration">0</item>
+ <item name="tabTextAppearance">@style/SettingsLibTabsTextAppearance</item>
+ <item name="tabTextColor">@color/settingslib_tabs_text_color</item>
+ </style>
+</resources>
\ No newline at end of file
diff --git a/packages/SystemUI/docs/keyguard.md b/packages/SystemUI/docs/keyguard.md
index 5e7bc1c..8914042 100644
--- a/packages/SystemUI/docs/keyguard.md
+++ b/packages/SystemUI/docs/keyguard.md
@@ -40,7 +40,7 @@
[1]: /frameworks/base/packages/SystemUI/docs/keyguard/bouncer.md
[2]: /frameworks/base/services/core/java/com/android/server/power/PowerManagerService.java
-[3]: /frameworks/base/packages/SystemUI/docs/keyguard/aod.md
+[3]: /frameworks/base/packages/SystemUI/docs/keyguard/doze.md
[4]: /frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java
diff --git a/packages/SystemUI/docs/keyguard/aod.md b/packages/SystemUI/docs/keyguard/aod.md
deleted file mode 100644
index 7f89984..0000000
--- a/packages/SystemUI/docs/keyguard/aod.md
+++ /dev/null
@@ -1,77 +0,0 @@
-# Always-on Display (AOD)
-
-AOD provides an alternatative 'screen-off' experience. Instead, of completely turning the display off, it provides a distraction-free, glanceable experience for the phone in a low-powered mode. In this low-powered mode, the display will have a lower refresh rate and the UI should frequently shift its displayed contents in order to prevent burn-in.
-
-The default doze component is specified by `config_dozeComponent` in the [framework config][1]. SystemUI provides a default Doze Component: [DozeService][2]. [DozeService][2] builds a [DozeMachine][3] with dependencies specified in [DozeModule][4] and configurations in [AmbientDisplayConfiguration][13] and [DozeParameters][14].
-
-[DozeMachine][3] handles the following main states:
-* AOD - persistently showing UI when the device is in a low-powered state
-* Pulsing - waking up the screen to show notifications (from AOD and screen off)
-* Docked UI - UI to show when the device is docked
-* Wake-up gestures - including lift to wake and tap to wake (from AOD and screen off)
-
-## Doze States ([see DozeMachine.State][3])
-### DOZE
-Device is asleep and listening for enabled pulsing and wake-up gesture triggers. In this state, no UI shows.
-
-### DOZE_AOD
-Device is asleep, showing UI, and listening for enabled pulsing and wake-up triggers. In this state, screen brightness is handled by [DozeScreenBrightness][5] which uses the brightness sensor specified by `doze_brightness_sensor_type` in the [SystemUI config][6]. To save power, this should be a low-powered sensor that shouldn't trigger as often as the light sensor used for on-screen adaptive brightness.
-
-### DOZE_AOD_PAUSED
-Device is asleep and would normally be in state `DOZE_AOD`; however, instead the display is temporarily off since the proximity sensor reported near for a minimum abount of time. [DozePauser][7] handles transitioning from `DOZE_AOD_PAUSING` after the minimum timeout after the NEAR is reported by the proximity sensor from [DozeTriggers][8]).
-
-### DOZE_PULSING
-Device is awake and showing UI. This is state typically occurs in response to incoming notification, but may also be from other pulse triggers specified in [DozeTriggers][8].
-
-### DOZE_AOD_DOCKED
-Device is awake, showing docking UI and listening for enabled pulsing and wake-up triggers. The default DockManager is provided by an empty interface at [DockManagerImpl][9]. SystemUI should override the DockManager for the DozeService to handle docking events.
-
-[DozeDockHandler][11] listens for Dock state changes from [DockManager][10] and updates the doze docking state.
-
-## Wake-up gestures
-Doze sensors are registered in [DozeTriggers][8] via [DozeSensors][12]. Sensors can be configured per posture for foldable devices.
-
-Relevant sensors include:
-* Proximity sensor
-* Brightness sensor
-* Wake-up gestures
- * tap to wake
- * double tap to wake
- * lift to wake
- * significant motion
-
-And are configured in the [AmbientDisplayConfiguration][13] with some related configurations specified in [DozeParameters][14].
-
-## Debugging Tips
-Enable DozeLog to print directly to logcat:
-```
-adb shell settings put global systemui/buffer/DozeLog v
-```
-
-Enable all DozeService logs to print directly to logcat:
-```
-adb shell setprop log.tag.DozeService DEBUG
-```
-
-Other helpful dumpsys commands (`adb shell dumpsys <service>`):
-* activity service com.android.systemui/.doze.DozeService
-* activity service com.android.systemui/.SystemUIService
-* display
-* power
-* dreams
-* sensorservice
-
-[1]: /frameworks/base/core/res/res/values/config.xml
-[2]: /frameworks/base/packages/SystemUI/src/com/android/systemui/doze/DozeService.java
-[3]: /frameworks/base/packages/SystemUI/src/com/android/systemui/doze/DozeMachine.java
-[4]: /frameworks/base/packages/SystemUI/src/com/android/systemui/doze/dagger/DozeModule.java
-[5]: /frameworks/base/packages/SystemUI/src/com/android/systemui/doze/DozeScreenBrightness.java
-[6]: /frameworks/base/packages/SystemUI/res/values/config.xml
-[7]: /frameworks/base/packages/SystemUI/src/com/android/systemui/doze/DozePauser.java
-[8]: /frameworks/base/packages/SystemUI/src/com/android/systemui/doze/DozeTriggers.java
-[9]: /frameworks/base/packages/SystemUI/src/com/android/systemui/dock/DockManagerImpl.java
-[10]: /frameworks/base/packages/SystemUI/src/com/android/systemui/dock/DockManager.java
-[11]: /frameworks/base/packages/SystemUI/src/com/android/systemui/doze/DozeDockHandler.java
-[12]: /frameworks/base/packages/SystemUI/src/com/android/systemui/doze/DozeSensors.java
-[13]: /frameworks/base/core/java/android/hardware/display/AmbientDisplayConfiguration.java
-[14]: /frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/DozeParameters.java
diff --git a/packages/SystemUI/docs/keyguard/doze.md b/packages/SystemUI/docs/keyguard/doze.md
new file mode 100644
index 0000000..a6ccab9
--- /dev/null
+++ b/packages/SystemUI/docs/keyguard/doze.md
@@ -0,0 +1,100 @@
+# Doze
+
+Always-on Display (AOD) provides an alternative 'screen-off' experience. Instead, of completely turning the display off, it provides a distraction-free, glanceable experience for the phone in a low-powered mode. In this low-powered mode, the display will have a lower refresh rate and the UI should frequently shift its displayed contents in order to prevent burn-in. The recommended max on-pixel-ratio (OPR) is 5% to reduce battery consumption.
+
+The default doze component controls AOD and is specified by `config_dozeComponent` in the [framework config][1]. SystemUI provides a default Doze Component: [DozeService][2]. [DozeService][2] builds a [DozeMachine][3] with dependencies specified in [DozeModule][4] and configurations in [AmbientDisplayConfiguration][13] and [DozeParameters][14].
+
+Note: The default UI used in AOD shares views with the Lock Screen and does not create its own new views. Once dozing begins, [DozeUI][17] informs SystemUI's [DozeServiceHost][18] that dozing has begun - which sends this signal to relevant SystemUI Lock Screen views to animate accordingly. Within SystemUI, [StatusBarStateController][19] #isDozing and #getDozeAmount can be used to query dozing state.
+[DozeMachine][3] handles the following main states:
+* AOD - persistently showing UI when the device is in a low-powered state
+* Pulsing - waking up the screen to show notifications (from AOD and screen off)
+* Docked UI - UI to show when the device is docked
+* Wake-up gestures - including lift to wake and tap to wake (from AOD and screen off)
+
+## Doze States ([see DozeMachine.State][3])
+### DOZE
+Device is asleep and listening for enabled pulsing and wake-up gesture triggers. In this state, no UI shows.
+
+### DOZE_AOD
+Device is asleep, showing UI, and listening for enabled pulsing and wake-up triggers. In this state, screen brightness is handled by [DozeScreenBrightness][5] which uses the brightness sensor specified by `doze_brightness_sensor_type` in the [SystemUI config][6]. To save power, this should be a low-powered sensor that shouldn't trigger as often as the light sensor used for on-screen adaptive brightness.
+
+### DOZE_AOD_PAUSED
+Device is asleep and would normally be in state `DOZE_AOD`; however, instead the display is temporarily off since the proximity sensor reported near for a minimum abount of time. [DozePauser][7] handles transitioning from `DOZE_AOD_PAUSING` after the minimum timeout after the NEAR is reported by the proximity sensor from [DozeTriggers][8]).
+
+### DOZE_PULSING
+Device is awake and showing UI. This is state typically occurs in response to incoming notification, but may also be from other pulse triggers specified in [DozeTriggers][8].
+
+### DOZE_AOD_DOCKED
+Device is awake, showing docking UI and listening for enabled pulsing and wake-up triggers. The default DockManager is provided by an empty interface at [DockManagerImpl][9]. SystemUI should override the DockManager for the DozeService to handle docking events.
+
+[DozeDockHandler][11] listens for Dock state changes from [DockManager][10] and updates the doze docking state.
+
+## Wake-up gestures
+Doze sensors are registered in [DozeTriggers][8] via [DozeSensors][12]. Sensors can be configured per posture for foldable devices.
+
+Relevant sensors include:
+* Proximity sensor
+* Brightness sensor
+* Wake-up gestures
+ * tap to wake
+ * double tap to wake
+ * lift to wake
+ * significant motion
+
+And are configured in the [AmbientDisplayConfiguration][13] with some related configurations specified in [DozeParameters][14].
+
+## Doze Suppressors
+When Dozing is enabled, it can still be suppressed based on the device state. On a high-level, doze and/or AOD may be suppressed if the device is:
+* in CAR_MODE
+* not provisioned
+* in power saver mode
+* being suppressed by an app (see [PowerManager#suppressAmbientDisplay][16])
+
+Refer to the documentation in [DozeSuppressors][15] for more information.
+
+## AOD burn-in and image retention
+Because AOD will show an image on the screen for an elogated period of time, AOD designs must take into consideration burn-in (leaving a permanent mark on the screen). Temporary burn-in is called image-retention.
+
+To prevent burn-in, it is recommended to often shift UI on the screen. [DozeUi][17] schedules a call to dozeTimeTick every minute to request a shift in UI for all elements on AOD. The amount of shift can be determined by undergoing simulated AOD testing since this may vary depending on the display.
+
+For manual local testing, set [DozeUI][17]#BURN_IN_TESTING_ENABLED to true, and then manual time broadcasts (ie: `adb shell 'date 022202222022.00 ; am broadcast -a android.intent.action.TIME_SET'`) will update the burn-in translations of the views. For a general idea where burn-in may be an issue, run the [software burn-in script][20].
+
+## Debugging Tips
+Enable DozeLog to print directly to logcat:
+```
+adb shell settings put global systemui/buffer/DozeLog v
+```
+
+Enable all DozeService logs to print directly to logcat:
+```
+adb shell setprop log.tag.DozeService DEBUG
+```
+
+Other helpful dumpsys commands (`adb shell dumpsys <service>`):
+* activity service com.android.systemui/.doze.DozeService
+* activity service com.android.systemui/.SystemUIService
+* display
+* power
+* dreams
+* sensorservice
+
+[1]: /frameworks/base/core/res/res/values/config.xml
+[2]: /frameworks/base/packages/SystemUI/src/com/android/systemui/doze/DozeService.java
+[3]: /frameworks/base/packages/SystemUI/src/com/android/systemui/doze/DozeMachine.java
+[4]: /frameworks/base/packages/SystemUI/src/com/android/systemui/doze/dagger/DozeModule.java
+[5]: /frameworks/base/packages/SystemUI/src/com/android/systemui/doze/DozeScreenBrightness.java
+[6]: /frameworks/base/packages/SystemUI/res/values/config.xml
+[7]: /frameworks/base/packages/SystemUI/src/com/android/systemui/doze/DozePauser.java
+[8]: /frameworks/base/packages/SystemUI/src/com/android/systemui/doze/DozeTriggers.java
+[9]: /frameworks/base/packages/SystemUI/src/com/android/systemui/dock/DockManagerImpl.java
+[10]: /frameworks/base/packages/SystemUI/src/com/android/systemui/dock/DockManager.java
+[11]: /frameworks/base/packages/SystemUI/src/com/android/systemui/doze/DozeDockHandler.java
+[12]: /frameworks/base/packages/SystemUI/src/com/android/systemui/doze/DozeSensors.java
+[13]: /frameworks/base/core/java/android/hardware/display/AmbientDisplayConfiguration.java
+[14]: /frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/DozeParameters.java
+[15]: /frameworks/base/packages/SystemUI/src/com/android/systemui/doze/DozeSuppressor.java
+[16]: /frameworks/base/core/java/android/os/PowerManager.java
+[17]: /frameworks/base/packages/SystemUI/src/com/android/systemui/doze/DozeUi.java
+[18]: /frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/DozeServiceHost.java
+[19]: /frameworks/base/packages/SystemUI/plugin/src/com/android/systemui/plugins/statusbar/StatusBarStateController.java
+[20]: /frameworks/base/packages/SystemUI/docs/clock-plugins.md
diff --git a/packages/SystemUI/res/values/config.xml b/packages/SystemUI/res/values/config.xml
index 9b1ba2f..83e6a54 100644
--- a/packages/SystemUI/res/values/config.xml
+++ b/packages/SystemUI/res/values/config.xml
@@ -487,6 +487,9 @@
space -->
<bool name="config_showBatteryEstimateQSBH">false</bool>
+ <!-- Whether to show a severe low battery dialog. -->
+ <bool name="config_severe_battery_dialog">false</bool>
+
<!-- A path similar to frameworks/base/core/res/res/values/config.xml
config_mainBuiltInDisplayCutout that describes a path larger than the exact path of a display
cutout. If present as well as config_enableDisplayCutoutProtection is set to true, then
diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml
index 06febbb..6d336e6 100644
--- a/packages/SystemUI/res/values/strings.xml
+++ b/packages/SystemUI/res/values/strings.xml
@@ -21,7 +21,13 @@
<string name="app_label">System UI</string>
<!-- When the battery is low, this is displayed to the user in a dialog. The title of the low battery alert. [CHAR LIMIT=NONE]-->
- <string name="battery_low_title">Battery may run out soon</string>
+ <string name="battery_low_title">Turn on Battery Saver?</string>
+
+ <!-- When the battery is low, this is displayed to the user in a dialog. The description of the low battery alert. [CHAR LIMIT=NONE]-->
+ <string name="battery_low_description">You have <xliff:g id="percentage" example="20%">%s</xliff:g> battery left. Battery Saver turns on Dark theme, restricts background activity, and delays notifications.</string>
+
+ <!-- When the battery is low at first time, this is displayed to the user in a dialog. The description of the low battery alert. [CHAR LIMIT=NONE]-->
+ <string name="battery_low_intro">Battery Saver turns on Dark theme, restricts background activity, and delays notifications.</string>
<!-- A message that appears when the battery level is getting low in a dialog. This is
appended to the subtitle of the low battery alert. "percentage" is the percentage of battery
diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsAnimationView.java b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsAnimationView.java
index 7fdb5ea..9281eb8 100644
--- a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsAnimationView.java
+++ b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsAnimationView.java
@@ -34,8 +34,10 @@
* - optionally can override dozeTimeTick to adjust views for burn-in mitigation
*/
public abstract class UdfpsAnimationView extends FrameLayout {
- // mAlpha takes into consideration the status bar expansion amount to fade out icon when
- // the status bar is expanded
+ private float mDialogSuggestedAlpha = 1f;
+ private float mNotificationShadeExpansion = 0f;
+
+ // mAlpha takes into consideration the status bar expansion amount and dialog suggested alpha
private int mAlpha;
boolean mPauseAuth;
@@ -92,6 +94,10 @@
}
int calculateAlpha() {
+ int alpha = expansionToAlpha(mNotificationShadeExpansion);
+ alpha *= mDialogSuggestedAlpha;
+ mAlpha = alpha;
+
return mPauseAuth ? mAlpha : 255;
}
@@ -111,8 +117,26 @@
return (int) ((1 - percent) * 255);
}
+ /**
+ * Set the suggested alpha based on whether a dialog was recently shown or hidden.
+ * @param dialogSuggestedAlpha value from 0f to 1f.
+ */
+ public void setDialogSuggestedAlpha(float dialogSuggestedAlpha) {
+ mDialogSuggestedAlpha = dialogSuggestedAlpha;
+ updateAlpha();
+ }
+
+ public float getDialogSuggestedAlpha() {
+ return mDialogSuggestedAlpha;
+ }
+
+ /**
+ * Sets the amount the notification shade is expanded. This will influence the opacity of the
+ * this visual affordance.
+ * @param expansion amount the shade has expanded from 0f to 1f.
+ */
public void onExpansionChanged(float expansion) {
- mAlpha = expansionToAlpha(expansion);
+ mNotificationShadeExpansion = expansion;
updateAlpha();
}
diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsAnimationViewController.kt b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsAnimationViewController.kt
index c33cd8d..27b0592 100644
--- a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsAnimationViewController.kt
+++ b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsAnimationViewController.kt
@@ -15,10 +15,12 @@
*/
package com.android.systemui.biometrics
+import android.animation.ValueAnimator
import android.graphics.PointF
import android.graphics.RectF
import com.android.systemui.Dumpable
import com.android.systemui.dump.DumpManager
+import com.android.systemui.animation.Interpolators
import com.android.systemui.plugins.statusbar.StatusBarStateController
import com.android.systemui.statusbar.phone.SystemUIDialogManager
import com.android.systemui.statusbar.phone.panelstate.PanelExpansionListener
@@ -50,7 +52,8 @@
private val view: T
get() = mView!!
- private val dialogListener = SystemUIDialogManager.Listener { updatePauseAuth() }
+ private var dialogAlphaAnimator: ValueAnimator? = null
+ private val dialogListener = SystemUIDialogManager.Listener { runDialogAlphaAnimator() }
private val panelExpansionListener =
PanelExpansionListener { fraction, expanded, tracking ->
@@ -83,6 +86,29 @@
*/
open val paddingY: Int = 0
+ open fun updateAlpha() {
+ view.updateAlpha()
+ }
+
+ fun runDialogAlphaAnimator() {
+ val hideAffordance = dialogManager.shouldHideAffordance()
+ dialogAlphaAnimator?.cancel()
+ dialogAlphaAnimator = ValueAnimator.ofFloat(
+ view.calculateAlpha() / 255f,
+ if (hideAffordance) 0f else 1f)
+ .apply {
+ duration = if (hideAffordance) 83L else 200L
+ interpolator = if (hideAffordance) Interpolators.LINEAR else Interpolators.ALPHA_IN
+
+ addUpdateListener { animatedValue ->
+ view.setDialogSuggestedAlpha(animatedValue.animatedValue as Float)
+ updateAlpha()
+ updatePauseAuth()
+ }
+ start()
+ }
+ }
+
override fun onViewAttached() {
panelExpansionStateManager.addExpansionListener(panelExpansionListener)
dialogManager.registerListener(dialogListener)
@@ -106,6 +132,7 @@
pw.println("mNotificationShadeVisible=$notificationShadeVisible")
pw.println("shouldPauseAuth()=" + shouldPauseAuth())
pw.println("isPauseAuth=" + view.isPauseAuth)
+ pw.println("dialogSuggestedAlpha=" + view.dialogSuggestedAlpha)
}
/**
diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsKeyguardViewController.java b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsKeyguardViewController.java
index 5ac21ff..b8334a0 100644
--- a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsKeyguardViewController.java
+++ b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsKeyguardViewController.java
@@ -28,6 +28,7 @@
import com.android.keyguard.KeyguardUpdateMonitor;
import com.android.systemui.R;
import com.android.systemui.animation.ActivityLaunchAnimator;
+import com.android.systemui.animation.Interpolators;
import com.android.systemui.dump.DumpManager;
import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.statusbar.LockscreenShadeTransitionController;
@@ -112,6 +113,7 @@
mActivityLaunchAnimator = activityLaunchAnimator;
mUnlockedScreenOffDozeAnimator.setDuration(StackStateAnimator.ANIMATION_DURATION_STANDARD);
+ mUnlockedScreenOffDozeAnimator.setInterpolator(Interpolators.ALPHA_IN);
mUnlockedScreenOffDozeAnimator.addUpdateListener(
new ValueAnimator.AnimatorUpdateListener() {
@Override
@@ -245,7 +247,7 @@
return false;
}
- if (getDialogManager().shouldHideAffordance()) {
+ if (mView.getDialogSuggestedAlpha() == 0f) {
return true;
}
@@ -321,7 +323,8 @@
* Update alpha for the UDFPS lock screen affordance. The AoD UDFPS visual affordance's
* alpha is based on the doze amount.
*/
- private void updateAlpha() {
+ @Override
+ public void updateAlpha() {
// fade icon on transitions to showing the status bar, but if mUdfpsRequested, then
// the keyguard is occluded by some application - so instead use the input bouncer
// hidden amount to determine the fade
@@ -338,6 +341,10 @@
if (mIsLaunchingActivity && !mUdfpsRequested) {
alpha *= (1.0f - mActivityLaunchProgress);
}
+
+ // Fade out alpha when a dialog is shown
+ // Fade in alpha when a dialog is hidden
+ alpha *= mView.getDialogSuggestedAlpha();
}
mView.setUnpausedAlpha(alpha);
}
@@ -369,6 +376,7 @@
public void onStateChanged(int statusBarState) {
mStatusBarState = statusBarState;
mView.setStatusBarState(statusBarState);
+ updateAlpha();
updatePauseAuth();
}
};
diff --git a/packages/SystemUI/src/com/android/systemui/controls/controller/ControlsProviderLifecycleManager.kt b/packages/SystemUI/src/com/android/systemui/controls/controller/ControlsProviderLifecycleManager.kt
index d2ded71..5b38e5b 100644
--- a/packages/SystemUI/src/com/android/systemui/controls/controller/ControlsProviderLifecycleManager.kt
+++ b/packages/SystemUI/src/com/android/systemui/controls/controller/ControlsProviderLifecycleManager.kt
@@ -97,7 +97,11 @@
}
bindTryCount++
try {
- context.bindServiceAsUser(intent, serviceConnection, BIND_FLAGS, user)
+ val bound = context
+ .bindServiceAsUser(intent, serviceConnection, BIND_FLAGS, user)
+ if (!bound) {
+ context.unbindService(serviceConnection)
+ }
} catch (e: SecurityException) {
Log.e(TAG, "Failed to bind to service", e)
}
diff --git a/packages/SystemUI/src/com/android/systemui/log/dagger/LogModule.java b/packages/SystemUI/src/com/android/systemui/log/dagger/LogModule.java
index b323586..ae7a671 100644
--- a/packages/SystemUI/src/com/android/systemui/log/dagger/LogModule.java
+++ b/packages/SystemUI/src/com/android/systemui/log/dagger/LogModule.java
@@ -154,6 +154,28 @@
return factory.create("SwipeStatusBarAwayLog", 30);
}
+ /**
+ * Provides a logging buffer for logs related to the media tap-to-transfer chip on the sender
+ * device. See {@link com.android.systemui.media.taptotransfer.sender.MediaTttSenderLogger}.
+ */
+ @Provides
+ @SysUISingleton
+ @MediaTttSenderLogBuffer
+ public static LogBuffer provideMediaTttSenderLogBuffer(LogBufferFactory factory) {
+ return factory.create("MediaTttSender", 20);
+ }
+
+ /**
+ * Provides a logging buffer for logs related to the media tap-to-transfer chip on the receiver
+ * device. See {@link com.android.systemui.media.taptotransfer.receiver.MediaTttReceiverLogger}.
+ */
+ @Provides
+ @SysUISingleton
+ @MediaTttReceiverLogBuffer
+ public static LogBuffer provideMediaTttReceiverLogBuffer(LogBufferFactory factory) {
+ return factory.create("MediaTttReceiver", 20);
+ }
+
/** Allows logging buffers to be tweaked via adb on debug builds but not on prod builds. */
@Provides
@SysUISingleton
diff --git a/packages/SystemUI/src/com/android/systemui/log/dagger/MediaTttReceiverLogBuffer.java b/packages/SystemUI/src/com/android/systemui/log/dagger/MediaTttReceiverLogBuffer.java
new file mode 100644
index 0000000..5c572e8
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/log/dagger/MediaTttReceiverLogBuffer.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2022 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.log.dagger;
+
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import com.android.systemui.log.LogBuffer;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+
+import javax.inject.Qualifier;
+
+/**
+ * A {@link LogBuffer} for
+ * {@link com.android.systemui.media.taptotransfer.receiver.MediaTttReceiverLogger}.
+ */
+@Qualifier
+@Documented
+@Retention(RUNTIME)
+public @interface MediaTttReceiverLogBuffer {
+}
diff --git a/packages/SystemUI/src/com/android/systemui/log/dagger/MediaTttSenderLogBuffer.java b/packages/SystemUI/src/com/android/systemui/log/dagger/MediaTttSenderLogBuffer.java
new file mode 100644
index 0000000..edab8c3
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/log/dagger/MediaTttSenderLogBuffer.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2022 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.log.dagger;
+
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import com.android.systemui.log.LogBuffer;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+
+import javax.inject.Qualifier;
+
+/**
+ * A {@link LogBuffer} for
+ * {@link com.android.systemui.media.taptotransfer.sender.MediaTttSenderLogger}.
+ */
+@Qualifier
+@Documented
+@Retention(RUNTIME)
+public @interface MediaTttSenderLogBuffer {
+}
diff --git a/packages/SystemUI/src/com/android/systemui/media/dagger/MediaModule.java b/packages/SystemUI/src/com/android/systemui/media/dagger/MediaModule.java
index c3b4354..66c036c 100644
--- a/packages/SystemUI/src/com/android/systemui/media/dagger/MediaModule.java
+++ b/packages/SystemUI/src/com/android/systemui/media/dagger/MediaModule.java
@@ -17,6 +17,9 @@
package com.android.systemui.media.dagger;
import com.android.systemui.dagger.SysUISingleton;
+import com.android.systemui.log.LogBuffer;
+import com.android.systemui.log.dagger.MediaTttReceiverLogBuffer;
+import com.android.systemui.log.dagger.MediaTttSenderLogBuffer;
import com.android.systemui.media.MediaDataManager;
import com.android.systemui.media.MediaFlags;
import com.android.systemui.media.MediaHierarchyManager;
@@ -27,8 +30,11 @@
import com.android.systemui.media.nearby.NearbyMediaDevicesManager;
import com.android.systemui.media.taptotransfer.MediaTttCommandLineHelper;
import com.android.systemui.media.taptotransfer.MediaTttFlags;
+import com.android.systemui.media.taptotransfer.common.MediaTttLogger;
import com.android.systemui.media.taptotransfer.receiver.MediaTttChipControllerReceiver;
+import com.android.systemui.media.taptotransfer.receiver.MediaTttReceiverLogger;
import com.android.systemui.media.taptotransfer.sender.MediaTttChipControllerSender;
+import com.android.systemui.media.taptotransfer.sender.MediaTttSenderLogger;
import java.util.Optional;
@@ -112,6 +118,24 @@
return Optional.of(controllerReceiverLazy.get());
}
+ @Provides
+ @SysUISingleton
+ @MediaTttSenderLogger
+ static MediaTttLogger providesMediaTttSenderLogger(
+ @MediaTttSenderLogBuffer LogBuffer buffer
+ ) {
+ return new MediaTttLogger("Sender", buffer);
+ }
+
+ @Provides
+ @SysUISingleton
+ @MediaTttReceiverLogger
+ static MediaTttLogger providesMediaTttReceiverLogger(
+ @MediaTttReceiverLogBuffer LogBuffer buffer
+ ) {
+ return new MediaTttLogger("Receiver", buffer);
+ }
+
/** */
@Provides
@SysUISingleton
diff --git a/packages/SystemUI/src/com/android/systemui/media/taptotransfer/common/MediaTttChipControllerCommon.kt b/packages/SystemUI/src/com/android/systemui/media/taptotransfer/common/MediaTttChipControllerCommon.kt
index 15b8f13..9c4b39d 100644
--- a/packages/SystemUI/src/com/android/systemui/media/taptotransfer/common/MediaTttChipControllerCommon.kt
+++ b/packages/SystemUI/src/com/android/systemui/media/taptotransfer/common/MediaTttChipControllerCommon.kt
@@ -43,6 +43,7 @@
*/
abstract class MediaTttChipControllerCommon<T : MediaTttChipState>(
internal val context: Context,
+ internal val logger: MediaTttLogger,
private val windowManager: WindowManager,
private val viewUtil: ViewUtil,
@Main private val mainExecutor: DelayableExecutor,
@@ -93,18 +94,26 @@
// Cancel and re-set the chip timeout each time we get a new state.
cancelChipViewTimeout?.run()
- cancelChipViewTimeout = mainExecutor.executeDelayed(this::removeChip, TIMEOUT_MILLIS)
+ cancelChipViewTimeout = mainExecutor.executeDelayed(
+ { removeChip(MediaTttRemovalReason.REASON_TIMEOUT) },
+ chipState.getTimeoutMs()
+ )
}
- /** Hides the chip. */
- fun removeChip() {
- // TODO(b/203800347): We may not want to hide the chip if we're currently in a
- // TransferTriggered state: Once the user has initiated the transfer, they should be able
- // to move away from the receiver device but still see the status of the transfer.
+ /**
+ * Hides the chip.
+ *
+ * @param removalReason a short string describing why the chip was removed (timeout, state
+ * change, etc.)
+ */
+ open fun removeChip(removalReason: String) {
if (chipView == null) { return }
+ logger.logChipRemoval(removalReason)
tapGestureDetector.removeOnGestureDetectedCallback(TAG)
windowManager.removeView(chipView)
chipView = null
+ // No need to time the chip out since it's already gone
+ cancelChipViewTimeout?.run()
}
/**
@@ -136,7 +145,7 @@
// If the tap is within the chip bounds, we shouldn't hide the chip (in case users think the
// chip is tappable).
if (!viewUtil.touchIsWithinView(view, e.x, e.y)) {
- removeChip()
+ removeChip(MediaTttRemovalReason.REASON_SCREEN_TAP)
}
}
}
@@ -145,5 +154,9 @@
// UpdateMediaTapToTransferReceiverDisplayTest
private const val WINDOW_TITLE = "Media Transfer Chip View"
private val TAG = MediaTttChipControllerCommon::class.simpleName!!
-@VisibleForTesting
-const val TIMEOUT_MILLIS = 3000L
+
+object MediaTttRemovalReason {
+ const val REASON_TIMEOUT = "TIMEOUT"
+ const val REASON_SCREEN_TAP = "SCREEN_TAP"
+}
+
diff --git a/packages/SystemUI/src/com/android/systemui/media/taptotransfer/common/MediaTttChipState.kt b/packages/SystemUI/src/com/android/systemui/media/taptotransfer/common/MediaTttChipState.kt
index 2da48ce..6f60181 100644
--- a/packages/SystemUI/src/com/android/systemui/media/taptotransfer/common/MediaTttChipState.kt
+++ b/packages/SystemUI/src/com/android/systemui/media/taptotransfer/common/MediaTttChipState.kt
@@ -52,6 +52,14 @@
null
}
}
+
+ /**
+ * Returns the amount of time this chip should display on the screen before it times out and
+ * disappears. [MediaTttChipControllerCommon] will ensure that the timeout resets each time we
+ * receive a new state.
+ */
+ open fun getTimeoutMs(): Long = DEFAULT_TIMEOUT_MILLIS
}
+private const val DEFAULT_TIMEOUT_MILLIS = 3000L
private val TAG = MediaTttChipState::class.simpleName!!
diff --git a/packages/SystemUI/src/com/android/systemui/media/taptotransfer/common/MediaTttLogger.kt b/packages/SystemUI/src/com/android/systemui/media/taptotransfer/common/MediaTttLogger.kt
new file mode 100644
index 0000000..d3b5bc6
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/media/taptotransfer/common/MediaTttLogger.kt
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2022 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.media.taptotransfer.common
+
+import com.android.systemui.log.LogBuffer
+import com.android.systemui.log.LogLevel
+import com.android.systemui.log.dagger.MediaTttSenderLogBuffer
+
+/**
+ * A logger for media tap-to-transfer events.
+ *
+ * @property deviceTypeTag the type of device triggering the logs -- "Sender" or "Receiver".
+ */
+class MediaTttLogger(
+ private val deviceTypeTag: String,
+ @MediaTttSenderLogBuffer private val buffer: LogBuffer
+){
+ /** Logs a change in the chip state for the given [mediaRouteId]. */
+ fun logStateChange(stateName: String, mediaRouteId: String) {
+ buffer.log(
+ BASE_TAG + deviceTypeTag,
+ LogLevel.DEBUG,
+ {
+ str1 = stateName
+ str2 = mediaRouteId
+ },
+ { "State changed to $str1 for ID=$str2" }
+ )
+ }
+
+ /** Logs that we removed the chip for the given [reason]. */
+ fun logChipRemoval(reason: String) {
+ buffer.log(
+ BASE_TAG + deviceTypeTag,
+ LogLevel.DEBUG,
+ { str1 = reason },
+ { "Chip removed due to $str1" }
+ )
+ }
+}
+
+private const val BASE_TAG = "MediaTtt"
diff --git a/packages/SystemUI/src/com/android/systemui/media/taptotransfer/receiver/MediaTttChipControllerReceiver.kt b/packages/SystemUI/src/com/android/systemui/media/taptotransfer/receiver/MediaTttChipControllerReceiver.kt
index 3d43ebe..1a96ddf 100644
--- a/packages/SystemUI/src/com/android/systemui/media/taptotransfer/receiver/MediaTttChipControllerReceiver.kt
+++ b/packages/SystemUI/src/com/android/systemui/media/taptotransfer/receiver/MediaTttChipControllerReceiver.kt
@@ -28,6 +28,7 @@
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.media.taptotransfer.common.MediaTttChipControllerCommon
+import com.android.systemui.media.taptotransfer.common.MediaTttLogger
import com.android.systemui.statusbar.CommandQueue
import com.android.systemui.statusbar.gesture.TapGestureDetector
import com.android.systemui.util.concurrency.DelayableExecutor
@@ -43,6 +44,7 @@
class MediaTttChipControllerReceiver @Inject constructor(
commandQueue: CommandQueue,
context: Context,
+ @MediaTttReceiverLogger logger: MediaTttLogger,
windowManager: WindowManager,
viewUtil: ViewUtil,
mainExecutor: DelayableExecutor,
@@ -50,6 +52,7 @@
@Main private val mainHandler: Handler,
) : MediaTttChipControllerCommon<ChipStateReceiver>(
context,
+ logger,
windowManager,
viewUtil,
mainExecutor,
@@ -79,6 +82,7 @@
appIcon: Icon?,
appName: CharSequence?
) {
+ logger.logStateChange(stateIntToString(displayState), routeInfo.id)
when(displayState) {
StatusBarManager.MEDIA_TRANSFER_RECEIVER_STATE_CLOSE_TO_SENDER -> {
val packageName = routeInfo.packageName
@@ -97,7 +101,8 @@
)
}
}
- StatusBarManager.MEDIA_TRANSFER_RECEIVER_STATE_FAR_FROM_SENDER -> removeChip()
+ StatusBarManager.MEDIA_TRANSFER_RECEIVER_STATE_FAR_FROM_SENDER ->
+ removeChip(removalReason = FAR_FROM_SENDER)
else ->
Log.e(RECEIVER_TAG, "Unhandled MediaTransferReceiverState $displayState")
}
@@ -106,6 +111,16 @@
override fun updateChipView(chipState: ChipStateReceiver, currentChipView: ViewGroup) {
setIcon(chipState, currentChipView)
}
+
+ private fun stateIntToString(@StatusBarManager.MediaTransferReceiverState state: Int): String {
+ return when (state) {
+ StatusBarManager.MEDIA_TRANSFER_RECEIVER_STATE_CLOSE_TO_SENDER -> CLOSE_TO_SENDER
+ StatusBarManager.MEDIA_TRANSFER_RECEIVER_STATE_FAR_FROM_SENDER -> FAR_FROM_SENDER
+ else -> "INVALID: $state"
+ }
+ }
}
private const val RECEIVER_TAG = "MediaTapToTransferRcvr"
+private const val CLOSE_TO_SENDER = "CLOSE_TO_SENDER"
+private const val FAR_FROM_SENDER = "FAR_FROM_SENDER"
diff --git a/packages/SystemUI/src/com/android/systemui/media/taptotransfer/receiver/MediaTttReceiverLogger.kt b/packages/SystemUI/src/com/android/systemui/media/taptotransfer/receiver/MediaTttReceiverLogger.kt
new file mode 100644
index 0000000..54fc48d
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/media/taptotransfer/receiver/MediaTttReceiverLogger.kt
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2022 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.media.taptotransfer.receiver
+
+import java.lang.annotation.Documented
+import java.lang.annotation.Retention
+import java.lang.annotation.RetentionPolicy
+import javax.inject.Qualifier
+
+@Qualifier
+@Documented
+@Retention(RetentionPolicy.RUNTIME)
+annotation class MediaTttReceiverLogger
diff --git a/packages/SystemUI/src/com/android/systemui/media/taptotransfer/sender/ChipStateSender.kt b/packages/SystemUI/src/com/android/systemui/media/taptotransfer/sender/ChipStateSender.kt
index 9b537fb..22424a4 100644
--- a/packages/SystemUI/src/com/android/systemui/media/taptotransfer/sender/ChipStateSender.kt
+++ b/packages/SystemUI/src/com/android/systemui/media/taptotransfer/sender/ChipStateSender.kt
@@ -97,6 +97,7 @@
}
override fun showLoading() = true
+ override fun getTimeoutMs() = TRANSFER_TRIGGERED_TIMEOUT_MILLIS
}
/**
@@ -111,6 +112,7 @@
}
override fun showLoading() = true
+ override fun getTimeoutMs() = TRANSFER_TRIGGERED_TIMEOUT_MILLIS
}
/**
@@ -194,3 +196,8 @@
return context.getString(R.string.media_transfer_failed)
}
}
+
+// Give the Transfer*Triggered states a longer timeout since those states represent an active
+// process and we should keep the user informed about it as long as possible (but don't allow it to
+// continue indefinitely).
+private const val TRANSFER_TRIGGERED_TIMEOUT_MILLIS = 15000L
\ No newline at end of file
diff --git a/packages/SystemUI/src/com/android/systemui/media/taptotransfer/sender/MediaTttChipControllerSender.kt b/packages/SystemUI/src/com/android/systemui/media/taptotransfer/sender/MediaTttChipControllerSender.kt
index 180e4ee..da2aac4 100644
--- a/packages/SystemUI/src/com/android/systemui/media/taptotransfer/sender/MediaTttChipControllerSender.kt
+++ b/packages/SystemUI/src/com/android/systemui/media/taptotransfer/sender/MediaTttChipControllerSender.kt
@@ -29,6 +29,8 @@
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.media.taptotransfer.common.MediaTttChipControllerCommon
+import com.android.systemui.media.taptotransfer.common.MediaTttLogger
+import com.android.systemui.media.taptotransfer.common.MediaTttRemovalReason
import com.android.systemui.statusbar.CommandQueue
import com.android.systemui.statusbar.gesture.TapGestureDetector
import com.android.systemui.util.concurrency.DelayableExecutor
@@ -43,13 +45,22 @@
class MediaTttChipControllerSender @Inject constructor(
commandQueue: CommandQueue,
context: Context,
+ @MediaTttSenderLogger logger: MediaTttLogger,
windowManager: WindowManager,
viewUtil: ViewUtil,
@Main mainExecutor: DelayableExecutor,
tapGestureDetector: TapGestureDetector,
) : MediaTttChipControllerCommon<ChipStateSender>(
- context, windowManager, viewUtil, mainExecutor, tapGestureDetector, R.layout.media_ttt_chip
+ context,
+ logger,
+ windowManager,
+ viewUtil,
+ mainExecutor,
+ tapGestureDetector,
+ R.layout.media_ttt_chip
) {
+ private var currentlyDisplayedChipState: ChipStateSender? = null
+
private val commandQueueCallbacks = object : CommandQueue.Callbacks {
override fun updateMediaTapToTransferSenderDisplay(
@StatusBarManager.MediaTransferSenderState displayState: Int,
@@ -71,6 +82,7 @@
routeInfo: MediaRoute2Info,
undoCallback: IUndoMediaTransferCallback?
) {
+ logger.logStateChange(stateIntToString(displayState), routeInfo.id)
val appPackageName = routeInfo.packageName
val otherDeviceName = routeInfo.name.toString()
val chipState = when(displayState) {
@@ -90,7 +102,7 @@
StatusBarManager.MEDIA_TRANSFER_SENDER_STATE_TRANSFER_TO_THIS_DEVICE_FAILED ->
TransferFailed(appPackageName)
StatusBarManager.MEDIA_TRANSFER_SENDER_STATE_FAR_FROM_RECEIVER -> {
- removeChip()
+ removeChip(removalReason = FAR_FROM_RECEIVER)
null
}
else -> {
@@ -106,6 +118,8 @@
/** Displays the chip view for the given state. */
override fun updateChipView(chipState: ChipStateSender, currentChipView: ViewGroup) {
+ currentlyDisplayedChipState = chipState
+
// App icon
setIcon(chipState, currentChipView)
@@ -129,6 +143,43 @@
currentChipView.requireViewById<View>(R.id.failure_icon).visibility =
if (showFailure) { View.VISIBLE } else { View.GONE }
}
+
+ override fun removeChip(removalReason: String) {
+ // Don't remove the chip if we're mid-transfer since the user should still be able to
+ // see the status of the transfer. (But do remove it if it's finally timed out.)
+ if ((currentlyDisplayedChipState is TransferToReceiverTriggered ||
+ currentlyDisplayedChipState is TransferToThisDeviceTriggered)
+ && removalReason != MediaTttRemovalReason.REASON_TIMEOUT) {
+ return
+ }
+ super.removeChip(removalReason)
+ currentlyDisplayedChipState = null
+ }
+
+ private fun stateIntToString(@StatusBarManager.MediaTransferSenderState state: Int): String {
+ return when(state) {
+ StatusBarManager.MEDIA_TRANSFER_SENDER_STATE_ALMOST_CLOSE_TO_START_CAST ->
+ "ALMOST_CLOSE_TO_START_CAST"
+ StatusBarManager.MEDIA_TRANSFER_SENDER_STATE_ALMOST_CLOSE_TO_END_CAST ->
+ "ALMOST_CLOSE_TO_END_CAST"
+ StatusBarManager.MEDIA_TRANSFER_SENDER_STATE_TRANSFER_TO_RECEIVER_TRIGGERED ->
+ "TRANSFER_TO_RECEIVER_TRIGGERED"
+ StatusBarManager.MEDIA_TRANSFER_SENDER_STATE_TRANSFER_TO_THIS_DEVICE_TRIGGERED ->
+ "TRANSFER_TO_THIS_DEVICE_TRIGGERED"
+ StatusBarManager.MEDIA_TRANSFER_SENDER_STATE_TRANSFER_TO_RECEIVER_SUCCEEDED ->
+ "TRANSFER_TO_RECEIVER_SUCCEEDED"
+ StatusBarManager.MEDIA_TRANSFER_SENDER_STATE_TRANSFER_TO_THIS_DEVICE_SUCCEEDED ->
+ "TRANSFER_TO_THIS_DEVICE_SUCCEEDED"
+ StatusBarManager.MEDIA_TRANSFER_SENDER_STATE_TRANSFER_TO_RECEIVER_FAILED ->
+ "TRANSFER_TO_RECEIVER_FAILED"
+ StatusBarManager.MEDIA_TRANSFER_SENDER_STATE_TRANSFER_TO_THIS_DEVICE_FAILED ->
+ "TRANSFER_TO_THIS_DEVICE_FAILED"
+ StatusBarManager.MEDIA_TRANSFER_SENDER_STATE_FAR_FROM_RECEIVER ->
+ FAR_FROM_RECEIVER
+ else -> "INVALID: $state"
+ }
+ }
}
const val SENDER_TAG = "MediaTapToTransferSender"
+private const val FAR_FROM_RECEIVER = "FAR_FROM_RECEIVER"
diff --git a/packages/SystemUI/src/com/android/systemui/media/taptotransfer/sender/MediaTttSenderLogger.kt b/packages/SystemUI/src/com/android/systemui/media/taptotransfer/sender/MediaTttSenderLogger.kt
new file mode 100644
index 0000000..4393af9
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/media/taptotransfer/sender/MediaTttSenderLogger.kt
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2022 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.media.taptotransfer.sender
+
+import java.lang.annotation.Documented
+import java.lang.annotation.Retention
+import java.lang.annotation.RetentionPolicy
+import javax.inject.Qualifier
+
+@Qualifier
+@Documented
+@Retention(RetentionPolicy.RUNTIME)
+annotation class MediaTttSenderLogger
diff --git a/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBar.java b/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBar.java
index 3ab1216..ec6094d 100644
--- a/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBar.java
+++ b/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBar.java
@@ -757,7 +757,8 @@
| WindowManager.LayoutParams.FLAG_SLIPPERY,
PixelFormat.TRANSLUCENT);
mOrientationParams.setTitle("SecondaryHomeHandle" + mContext.getDisplayId());
- mOrientationParams.privateFlags |= PRIVATE_FLAG_NO_MOVE_ANIMATION;
+ mOrientationParams.privateFlags |= PRIVATE_FLAG_NO_MOVE_ANIMATION
+ | WindowManager.LayoutParams.PRIVATE_FLAG_LAYOUT_SIZE_EXTENDED_BY_CUTOUT;
mWindowManager.addView(mOrientationHandle, mOrientationParams);
mOrientationHandle.setVisibility(View.GONE);
mOrientationParams.setFitInsetsTypes(0 /* types*/);
@@ -1565,7 +1566,8 @@
}
lp.token = new Binder();
lp.accessibilityTitle = mContext.getString(R.string.nav_bar);
- lp.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COLOR_SPACE_AGNOSTIC;
+ lp.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COLOR_SPACE_AGNOSTIC
+ | WindowManager.LayoutParams.PRIVATE_FLAG_LAYOUT_SIZE_EXTENDED_BY_CUTOUT;
lp.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
lp.windowAnimations = 0;
lp.setTitle("NavigationBar" + mContext.getDisplayId());
diff --git a/packages/SystemUI/src/com/android/systemui/power/PowerNotificationWarnings.java b/packages/SystemUI/src/com/android/systemui/power/PowerNotificationWarnings.java
index dbd641b..039c333 100644
--- a/packages/SystemUI/src/com/android/systemui/power/PowerNotificationWarnings.java
+++ b/packages/SystemUI/src/com/android/systemui/power/PowerNotificationWarnings.java
@@ -118,6 +118,8 @@
private static final String ACTION_AUTO_SAVER_NO_THANKS =
"PNW.autoSaverNoThanks";
+ private static final String ACTION_ENABLE_SEVERE_BATTERY_DIALOG = "PNW.enableSevereDialog";
+
private static final String SETTINGS_ACTION_OPEN_BATTERY_SAVER_SETTING =
"android.settings.BATTERY_SAVER_SETTINGS";
public static final String BATTERY_SAVER_SCHEDULE_SCREEN_INTENT_ACTION =
@@ -253,20 +255,25 @@
}
protected void showWarningNotification() {
- final String percentage = NumberFormat.getPercentInstance()
- .format((double) mCurrentBatterySnapshot.getBatteryLevel() / 100.0);
-
- // get shared standard notification copy
- String title = mContext.getString(R.string.battery_low_title);
- String contentText;
-
- // get correct content text if notification is hybrid or not
- if (mCurrentBatterySnapshot.isHybrid()) {
- contentText = getHybridContentString(percentage);
- } else {
- contentText = mContext.getString(R.string.battery_low_percent_format, percentage);
+ if (showSevereLowBatteryDialog()) {
+ mContext.sendBroadcast(new Intent(ACTION_ENABLE_SEVERE_BATTERY_DIALOG)
+ .setPackage(mContext.getPackageName())
+ .addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY
+ | Intent.FLAG_RECEIVER_FOREGROUND));
+ // Reset the state once dialog been enabled
+ dismissLowBatteryNotification();
+ mPlaySound = false;
+ return;
}
+ final int warningLevel = mContext.getResources().getInteger(
+ com.android.internal.R.integer.config_lowBatteryWarningLevel);
+ final String percentage = NumberFormat.getPercentInstance()
+ .format((double) warningLevel / 100.0);
+ final String title = mContext.getString(R.string.battery_low_title);
+ final String contentText = mContext.getString(
+ R.string.battery_low_description, percentage);
+
final Notification.Builder nb =
new Notification.Builder(mContext, NotificationChannels.BATTERY)
.setSmallIcon(R.drawable.ic_power_low)
@@ -284,7 +291,7 @@
}
// Make the notification red if the percentage goes below a certain amount or the time
// remaining estimate is disabled
- if (!mCurrentBatterySnapshot.isHybrid() || mBucket < 0
+ if (!mCurrentBatterySnapshot.isHybrid() || mBucket < -1
|| mCurrentBatterySnapshot.getTimeRemainingMillis()
< mCurrentBatterySnapshot.getSevereThresholdMillis()) {
nb.setColor(Utils.getColorAttrDefaultColor(mContext, android.R.attr.colorError));
@@ -303,6 +310,13 @@
mNoMan.notifyAsUser(TAG_BATTERY, SystemMessage.NOTE_POWER_LOW, n, UserHandle.ALL);
}
+ private boolean showSevereLowBatteryDialog() {
+ final boolean isSevereState = !mCurrentBatterySnapshot.isHybrid() || mBucket < -1;
+ final boolean useSevereDialog = mContext.getResources().getBoolean(
+ R.bool.config_severe_battery_dialog);
+ return isSevereState && useSevereDialog;
+ }
+
private void showAutoSaverSuggestionNotification() {
final CharSequence message = mContext.getString(R.string.auto_saver_text);
final Notification.Builder nb =
@@ -662,8 +676,7 @@
// If there's no link, use the string with no "learn more".
if (TextUtils.isEmpty(learnMoreUrl)) {
- return mContext.getText(
- com.android.internal.R.string.battery_saver_description);
+ return mContext.getText(R.string.battery_low_intro);
}
// If we have a link, use the string with the "learn more" link.
diff --git a/packages/SystemUI/src/com/android/systemui/power/PowerUI.java b/packages/SystemUI/src/com/android/systemui/power/PowerUI.java
index a7ed871..56528c9 100644
--- a/packages/SystemUI/src/com/android/systemui/power/PowerUI.java
+++ b/packages/SystemUI/src/com/android/systemui/power/PowerUI.java
@@ -69,7 +69,7 @@
private static final long TEMPERATURE_LOGGING_INTERVAL = DateUtils.HOUR_IN_MILLIS;
private static final int MAX_RECENT_TEMPS = 125; // TEMPERATURE_LOGGING_INTERVAL plus a buffer
static final long THREE_HOURS_IN_MILLIS = DateUtils.HOUR_IN_MILLIS * 3;
- private static final int CHARGE_CYCLE_PERCENT_RESET = 45;
+ private static final int CHARGE_CYCLE_PERCENT_RESET = 30;
private static final long SIX_HOURS_MILLIS = Duration.ofHours(6).toMillis();
public static final int NO_ESTIMATE_AVAILABLE = -1;
private static final String BOOT_COUNT_KEY = "boot_count";
@@ -206,7 +206,8 @@
*
* 1 means that the battery is "ok"
* 0 means that the battery is between "ok" and what we should warn about.
- * less than 0 means that the battery is low
+ * less than 0 means that the battery is low, -1 means the battery is reaching warning level,
+ * -2 means the battery is reaching severe level.
*/
private int findBatteryLevelBucket(int level) {
if (level >= mLowBatteryAlertCloseLevel) {
@@ -388,12 +389,8 @@
@VisibleForTesting
void maybeShowHybridWarning(BatteryStateSnapshot currentSnapshot,
BatteryStateSnapshot lastSnapshot) {
- // if we are now over 45% battery & 6 hours remaining so we can trigger hybrid
- // notification again
- final long timeRemainingMillis = currentSnapshot.getTimeRemainingMillis();
- if (currentSnapshot.getBatteryLevel() >= CHARGE_CYCLE_PERCENT_RESET
- && (timeRemainingMillis > SIX_HOURS_MILLIS
- || timeRemainingMillis == NO_ESTIMATE_AVAILABLE)) {
+ // if we are now over 30% battery, we can trigger hybrid notification again
+ if (currentSnapshot.getBatteryLevel() >= CHARGE_CYCLE_PERCENT_RESET) {
mLowWarningShownThisChargeCycle = false;
mSevereWarningShownThisChargeCycle = false;
if (DEBUG) {
@@ -403,6 +400,7 @@
final boolean playSound = currentSnapshot.getBucket() != lastSnapshot.getBucket()
|| lastSnapshot.getPlugged();
+ final long timeRemainingMillis = currentSnapshot.getTimeRemainingMillis();
if (shouldShowHybridWarning(currentSnapshot)) {
mWarnings.showLowBatteryWarning(playSound);
@@ -444,19 +442,13 @@
return false;
}
- final long timeRemainingMillis = snapshot.getTimeRemainingMillis();
// Only show the low warning if enabled once per charge cycle & no battery saver
- final boolean canShowWarning = snapshot.isLowWarningEnabled()
- && !mLowWarningShownThisChargeCycle && !snapshot.isPowerSaver()
- && ((timeRemainingMillis != NO_ESTIMATE_AVAILABLE
- && timeRemainingMillis < snapshot.getLowThresholdMillis())
- || snapshot.getBatteryLevel() <= snapshot.getLowLevelThreshold());
+ final boolean canShowWarning = !mLowWarningShownThisChargeCycle && !snapshot.isPowerSaver()
+ && snapshot.getBatteryLevel() <= snapshot.getLowLevelThreshold();
// Only show the severe warning once per charge cycle
final boolean canShowSevereWarning = !mSevereWarningShownThisChargeCycle
- && ((timeRemainingMillis != NO_ESTIMATE_AVAILABLE
- && timeRemainingMillis < snapshot.getSevereThresholdMillis())
- || snapshot.getBatteryLevel() <= snapshot.getSevereLevelThreshold());
+ && snapshot.getBatteryLevel() <= snapshot.getSevereLevelThreshold();
final boolean canShow = canShowWarning || canShowSevereWarning;
diff --git a/packages/SystemUI/src/com/android/systemui/qs/external/TileLifecycleManager.java b/packages/SystemUI/src/com/android/systemui/qs/external/TileLifecycleManager.java
index 32e0805..a49d3fd 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/external/TileLifecycleManager.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/external/TileLifecycleManager.java
@@ -204,6 +204,9 @@
| Context.BIND_ALLOW_BACKGROUND_ACTIVITY_STARTS
| Context.BIND_WAIVE_PRIORITY,
mUser);
+ if (!mIsBound) {
+ mContext.unbindService(this);
+ }
} catch (SecurityException e) {
Log.e(TAG, "Failed to bind to service", e);
mIsBound = false;
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfaces.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfaces.java
index 5642744..4235c1f 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfaces.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfaces.java
@@ -3972,8 +3972,14 @@
mActivityLaunchAnimator.startPendingIntentWithAnimation(
controller, animate, intent.getCreatorPackage(),
- (animationAdapter) -> intent.sendAndReturnResult(null, 0, null, null, null,
- null, getActivityOptions(mDisplayId, animationAdapter)));
+ (animationAdapter) -> {
+ ActivityOptions options = new ActivityOptions(
+ getActivityOptions(mDisplayId, animationAdapter));
+ // TODO b/221255671: restrict this to only be set for notifications
+ options.setEligibleForLegacyPermissionPrompt(true);
+ return intent.sendAndReturnResult(null, 0, null, null, null,
+ null, options.toBundle());
+ });
} catch (PendingIntent.CanceledException e) {
// the stack trace isn't very helpful here.
// Just log the exception message.
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/DozeParameters.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/DozeParameters.java
index 8b25c2b..ebe91c7 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/DozeParameters.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/DozeParameters.java
@@ -292,11 +292,20 @@
}
public void updateControlScreenOff() {
- if (!getDisplayNeedsBlanking()) {
- final boolean controlScreenOff =
- getAlwaysOn() && (mKeyguardShowing || shouldControlUnlockedScreenOff());
- setControlScreenOffAnimation(controlScreenOff);
- }
+ final boolean controlScreenOff = shouldControlUnlockedScreenOff()
+ || (!getDisplayNeedsBlanking() && getAlwaysOn() && mKeyguardShowing);
+ setControlScreenOffAnimation(controlScreenOff);
+ }
+
+ /**
+ * Whether we're capable of controlling the screen off animation if we want to. This isn't
+ * possible if AOD isn't even enabled or if the flag is disabled, or if the display needs
+ * blanking.
+ */
+ public boolean canControlUnlockedScreenOff() {
+ return getAlwaysOn()
+ && mFeatureFlags.isEnabled(Flags.LOCKSCREEN_ANIMATIONS)
+ && !getDisplayNeedsBlanking();
}
/**
@@ -309,8 +318,7 @@
* disabled for a11y.
*/
public boolean shouldControlUnlockedScreenOff() {
- return canControlUnlockedScreenOff()
- && mUnlockedScreenOffAnimationController.shouldPlayUnlockedScreenOffAnimation();
+ return mUnlockedScreenOffAnimationController.shouldPlayUnlockedScreenOffAnimation();
}
public boolean shouldDelayKeyguardShow() {
@@ -342,16 +350,6 @@
return getAlwaysOn() && mKeyguardShowing;
}
- /**
- * Whether we're capable of controlling the screen off animation if we want to. This isn't
- * possible if AOD isn't even enabled or if the flag is disabled.
- */
- public boolean canControlUnlockedScreenOff() {
- return getAlwaysOn()
- && mFeatureFlags.isEnabled(Flags.LOCKSCREEN_ANIMATIONS)
- && !getDisplayNeedsBlanking();
- }
-
private boolean getBoolean(String propName, int resId) {
return SystemProperties.getBoolean(propName, mResources.getBoolean(resId));
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/UnlockedScreenOffAnimationController.kt b/packages/SystemUI/src/com/android/systemui/statusbar/phone/UnlockedScreenOffAnimationController.kt
index c11d450..8b0eaec 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/UnlockedScreenOffAnimationController.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/UnlockedScreenOffAnimationController.kt
@@ -61,6 +61,14 @@
) : WakefulnessLifecycle.Observer, ScreenOffAnimation {
private lateinit var mCentralSurfaces: CentralSurfaces
+
+ /**
+ * Whether or not [initialize] has been called to provide us with the StatusBar,
+ * NotificationPanelViewController, and LightRevealSrim so that we can run the unlocked screen
+ * off animation.
+ */
+ private var initialized = false
+
private lateinit var lightRevealScrim: LightRevealScrim
private var animatorDurationScale = 1f
@@ -116,6 +124,7 @@
centralSurfaces: CentralSurfaces,
lightRevealScrim: LightRevealScrim
) {
+ this.initialized = true
this.lightRevealScrim = lightRevealScrim
this.mCentralSurfaces = centralSurfaces
@@ -262,6 +271,18 @@
* on the current state of the device.
*/
fun shouldPlayUnlockedScreenOffAnimation(): Boolean {
+ // If we haven't been initialized yet, we don't have a StatusBar/LightRevealScrim yet, so we
+ // can't perform the animation.
+ if (!initialized) {
+ return false
+ }
+
+ // If the device isn't in a state where we can control unlocked screen off (no AOD enabled,
+ // power save, etc.) then we shouldn't try to do so.
+ if (!dozeParameters.get().canControlUnlockedScreenOff()) {
+ return false
+ }
+
// If we explicitly already decided not to play the screen off animation, then never change
// our mind.
if (decidedToAnimateGoingToSleep == false) {
@@ -304,7 +325,7 @@
}
override fun shouldDelayDisplayDozeTransition(): Boolean =
- dozeParameters.get().shouldControlUnlockedScreenOff()
+ shouldPlayUnlockedScreenOffAnimation()
/**
* Whether we're doing the light reveal animation or we're done with that and animating in the
diff --git a/packages/SystemUI/tests/src/com/android/systemui/biometrics/UdfpsKeyguardViewControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/biometrics/UdfpsKeyguardViewControllerTest.java
index 7fb42b6..186f2bb 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/biometrics/UdfpsKeyguardViewControllerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/biometrics/UdfpsKeyguardViewControllerTest.java
@@ -124,6 +124,7 @@
when(mView.getContext()).thenReturn(mResourceContext);
when(mResourceContext.getString(anyInt())).thenReturn("test string");
when(mKeyguardViewMediator.isAnimatingScreenOff()).thenReturn(false);
+ when(mView.getDialogSuggestedAlpha()).thenReturn(1f);
mController = new UdfpsKeyguardViewController(
mView,
mStatusBarStateController,
@@ -144,7 +145,7 @@
@Test
public void testRegistersExpansionChangedListenerOnAttached() {
mController.onViewAttached();
- captureExpansionListeners();
+ captureStatusBarExpansionListeners();
}
@Test
@@ -173,7 +174,7 @@
public void testListenersUnregisteredOnDetached() {
mController.onViewAttached();
captureStatusBarStateListeners();
- captureExpansionListeners();
+ captureStatusBarExpansionListeners();
captureKeyguardStateControllerCallback();
mController.onViewDetached();
@@ -200,10 +201,41 @@
public void testShouldPauseAuthBouncerShowing() {
mController.onViewAttached();
captureStatusBarStateListeners();
-
sendStatusBarStateChanged(StatusBarState.KEYGUARD);
- assertFalse(mController.shouldPauseAuth());
+ captureAltAuthInterceptor();
+ when(mStatusBarKeyguardViewManager.isBouncerShowing()).thenReturn(true);
+ mAltAuthInterceptor.onBouncerVisibilityChanged();
+
+ assertTrue(mController.shouldPauseAuth());
+ }
+
+ @Test
+ public void testShouldPauseAuthDialogSuggestedAlpha0() {
+ mController.onViewAttached();
+ captureStatusBarStateListeners();
+
+ when(mView.getDialogSuggestedAlpha()).thenReturn(0f);
+ sendStatusBarStateChanged(StatusBarState.KEYGUARD);
+
+ assertTrue(mController.shouldPauseAuth());
+ }
+
+ @Test
+ public void testFadeFromDialogSuggestedAlpha() {
+ // GIVEN view is attached and status bar expansion is 1f
+ mController.onViewAttached();
+ captureStatusBarStateListeners();
+ captureStatusBarExpansionListeners();
+ updateStatusBarExpansion(1f, true);
+ reset(mView);
+
+ // WHEN dialog suggested alpha is .6f
+ when(mView.getDialogSuggestedAlpha()).thenReturn(.6f);
+ sendStatusBarStateChanged(StatusBarState.KEYGUARD);
+
+ // THEN alpha is updated based on dialog suggested alpha
+ verify(mView).setUnpausedAlpha((int) (.6f * 255));
}
@Test
@@ -367,7 +399,7 @@
public void testFadeInWithStatusBarExpansion() {
// GIVEN view is attached
mController.onViewAttached();
- captureExpansionListeners();
+ captureStatusBarExpansionListeners();
captureKeyguardStateControllerCallback();
reset(mView);
@@ -382,7 +414,7 @@
public void testShowUdfpsBouncer() {
// GIVEN view is attached and status bar expansion is 0
mController.onViewAttached();
- captureExpansionListeners();
+ captureStatusBarExpansionListeners();
captureKeyguardStateControllerCallback();
captureAltAuthInterceptor();
updateStatusBarExpansion(0, true);
@@ -401,9 +433,10 @@
public void testTransitionToFullShadeProgress() {
// GIVEN view is attached and status bar expansion is 1f
mController.onViewAttached();
- captureExpansionListeners();
+ captureStatusBarExpansionListeners();
updateStatusBarExpansion(1f, true);
reset(mView);
+ when(mView.getDialogSuggestedAlpha()).thenReturn(1f);
// WHEN we're transitioning to the full shade
float transitionProgress = .6f;
@@ -417,7 +450,7 @@
public void testShowUdfpsBouncer_transitionToFullShadeProgress() {
// GIVEN view is attached and status bar expansion is 1f
mController.onViewAttached();
- captureExpansionListeners();
+ captureStatusBarExpansionListeners();
captureKeyguardStateControllerCallback();
captureAltAuthInterceptor();
updateStatusBarExpansion(1f, true);
@@ -440,7 +473,7 @@
mStatusBarStateListener = mStateListenerCaptor.getValue();
}
- private void captureExpansionListeners() {
+ private void captureStatusBarExpansionListeners() {
verify(mPanelExpansionStateManager, times(2))
.addExpansionListener(mExpansionListenerCaptor.capture());
// first (index=0) is from super class, UdfpsAnimationViewController.
@@ -460,8 +493,6 @@
mAltAuthInterceptor = mAltAuthInterceptorCaptor.getValue();
}
-
-
private void captureKeyguardStateControllerCallback() {
verify(mKeyguardStateController).addCallback(
mKeyguardStateControllerCallbackCaptor.capture());
diff --git a/packages/SystemUI/tests/src/com/android/systemui/controls/controller/ControlsProviderLifecycleManagerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/controls/controller/ControlsProviderLifecycleManagerTest.kt
index 12096bc..af3f24a 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/controls/controller/ControlsProviderLifecycleManagerTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/controls/controller/ControlsProviderLifecycleManagerTest.kt
@@ -210,4 +210,25 @@
eq(actionCallbackService))
assertEquals(action, wrapperCaptor.getValue().getWrappedAction())
}
+
+ @Test
+ fun testFalseBindCallsUnbind() {
+ val falseContext = mock(Context::class.java)
+ `when`(falseContext.bindServiceAsUser(any(), any(), anyInt(), any())).thenReturn(false)
+ val manager = ControlsProviderLifecycleManager(
+ falseContext,
+ executor,
+ actionCallbackService,
+ UserHandle.of(0),
+ componentName
+ )
+ manager.bindService()
+ executor.runAllReady()
+
+ val captor = ArgumentCaptor.forClass(
+ ServiceConnection::class.java
+ )
+ verify(falseContext).bindServiceAsUser(any(), captor.capture(), anyInt(), any())
+ verify(falseContext).unbindService(captor.value)
+ }
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/dreams/DreamOverlayServiceTest.java b/packages/SystemUI/tests/src/com/android/systemui/dreams/DreamOverlayServiceTest.java
index 21768ed..2860b50 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/dreams/DreamOverlayServiceTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/dreams/DreamOverlayServiceTest.java
@@ -152,19 +152,19 @@
}
@Test
- public void testShouldShowComplicationsTrueByDefault() {
+ public void testShouldShowComplicationsFalseByDefault() {
mService.onBind(new Intent());
- assertThat(mService.shouldShowComplications()).isTrue();
+ assertThat(mService.shouldShowComplications()).isFalse();
}
@Test
public void testShouldShowComplicationsSetByIntentExtra() {
final Intent intent = new Intent();
- intent.putExtra(DreamService.EXTRA_SHOW_COMPLICATIONS, false);
+ intent.putExtra(DreamService.EXTRA_SHOW_COMPLICATIONS, true);
mService.onBind(intent);
- assertThat(mService.shouldShowComplications()).isFalse();
+ assertThat(mService.shouldShowComplications()).isTrue();
}
@Test
diff --git a/packages/SystemUI/tests/src/com/android/systemui/dreams/DreamOverlayStateControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/dreams/DreamOverlayStateControllerTest.java
index 49da4bd..3ce9889 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/dreams/DreamOverlayStateControllerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/dreams/DreamOverlayStateControllerTest.java
@@ -158,6 +158,7 @@
public void testComplicationFilteringWhenShouldShowComplications() {
final DreamOverlayStateController stateController =
new DreamOverlayStateController(mExecutor);
+ stateController.setShouldShowComplications(true);
final Complication alwaysAvailableComplication = Mockito.mock(Complication.class);
final Complication weatherComplication = Mockito.mock(Complication.class);
diff --git a/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/common/MediaTttChipControllerCommonTest.kt b/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/common/MediaTttChipControllerCommonTest.kt
index 809b890..adb59ec 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/common/MediaTttChipControllerCommonTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/common/MediaTttChipControllerCommonTest.kt
@@ -55,6 +55,8 @@
private lateinit var appIconDrawable: Drawable
@Mock
+ private lateinit var logger: MediaTttLogger
+ @Mock
private lateinit var windowManager: WindowManager
@Mock
private lateinit var viewUtil: ViewUtil
@@ -69,7 +71,7 @@
fakeExecutor = FakeExecutor(fakeClock)
controllerCommon = TestControllerCommon(
- context, windowManager, viewUtil, fakeExecutor, tapGestureDetector
+ context, logger, windowManager, viewUtil, fakeExecutor, tapGestureDetector
)
}
@@ -94,20 +96,22 @@
@Test
fun displayChip_chipDoesNotDisappearsBeforeTimeout() {
- controllerCommon.displayChip(getState())
+ val state = getState()
+ controllerCommon.displayChip(state)
reset(windowManager)
- fakeClock.advanceTime(TIMEOUT_MILLIS - 1)
+ fakeClock.advanceTime(state.getTimeoutMs() - 1)
verify(windowManager, never()).removeView(any())
}
@Test
fun displayChip_chipDisappearsAfterTimeout() {
- controllerCommon.displayChip(getState())
+ val state = getState()
+ controllerCommon.displayChip(state)
reset(windowManager)
- fakeClock.advanceTime(TIMEOUT_MILLIS + 1)
+ fakeClock.advanceTime(state.getTimeoutMs() + 1)
verify(windowManager).removeView(any())
}
@@ -115,7 +119,8 @@
@Test
fun displayChip_calledAgainBeforeTimeout_timeoutReset() {
// First, display the chip
- controllerCommon.displayChip(getState())
+ val state = getState()
+ controllerCommon.displayChip(state)
// After some time, re-display the chip
val waitTime = 1000L
@@ -123,7 +128,7 @@
controllerCommon.displayChip(getState())
// Wait until the timeout for the first display would've happened
- fakeClock.advanceTime(TIMEOUT_MILLIS - waitTime + 1)
+ fakeClock.advanceTime(state.getTimeoutMs() - waitTime + 1)
// Verify we didn't hide the chip
verify(windowManager, never()).removeView(any())
@@ -132,33 +137,36 @@
@Test
fun displayChip_calledAgainBeforeTimeout_eventuallyTimesOut() {
// First, display the chip
- controllerCommon.displayChip(getState())
+ val state = getState()
+ controllerCommon.displayChip(state)
// After some time, re-display the chip
fakeClock.advanceTime(1000L)
controllerCommon.displayChip(getState())
// Ensure we still hide the chip eventually
- fakeClock.advanceTime(TIMEOUT_MILLIS + 1)
+ fakeClock.advanceTime(state.getTimeoutMs() + 1)
verify(windowManager).removeView(any())
}
@Test
- fun removeChip_chipRemovedAndGestureDetectionStopped() {
+ fun removeChip_chipRemovedAndGestureDetectionStoppedAndRemovalLogged() {
// First, add the chip
controllerCommon.displayChip(getState())
// Then, remove it
- controllerCommon.removeChip()
+ val reason = "test reason"
+ controllerCommon.removeChip(reason)
verify(windowManager).removeView(any())
verify(tapGestureDetector).removeOnGestureDetectedCallback(any())
+ verify(logger).logChipRemoval(reason)
}
@Test
fun removeChip_noAdd_viewNotRemoved() {
- controllerCommon.removeChip()
+ controllerCommon.removeChip("reason")
verify(windowManager, never()).removeView(any())
}
@@ -222,12 +230,19 @@
inner class TestControllerCommon(
context: Context,
+ logger: MediaTttLogger,
windowManager: WindowManager,
viewUtil: ViewUtil,
@Main mainExecutor: DelayableExecutor,
tapGestureDetector: TapGestureDetector,
) : MediaTttChipControllerCommon<MediaTttChipState>(
- context, windowManager, viewUtil, mainExecutor, tapGestureDetector, R.layout.media_ttt_chip
+ context,
+ logger,
+ windowManager,
+ viewUtil,
+ mainExecutor,
+ tapGestureDetector,
+ R.layout.media_ttt_chip
) {
override fun updateChipView(chipState: MediaTttChipState, currentChipView: ViewGroup) {
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/common/MediaTttLoggerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/common/MediaTttLoggerTest.kt
new file mode 100644
index 0000000..d95e5c4
--- /dev/null
+++ b/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/common/MediaTttLoggerTest.kt
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2022 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.media.taptotransfer.common
+
+import androidx.test.filters.SmallTest
+import com.android.systemui.SysuiTestCase
+import com.android.systemui.dump.DumpManager
+import com.android.systemui.log.LogBuffer
+import com.android.systemui.log.LogBufferFactory
+import com.android.systemui.log.LogcatEchoTracker
+import com.google.common.truth.Truth.assertThat
+import org.junit.Before
+import org.junit.Test
+import org.mockito.Mockito.mock
+import java.io.PrintWriter
+import java.io.StringWriter
+
+@SmallTest
+class MediaTttLoggerTest : SysuiTestCase() {
+
+ private lateinit var buffer: LogBuffer
+ private lateinit var logger: MediaTttLogger
+
+ @Before
+ fun setUp () {
+ buffer = LogBufferFactory(DumpManager(), mock(LogcatEchoTracker::class.java))
+ .create("buffer", 10)
+ logger = MediaTttLogger(DEVICE_TYPE_TAG, buffer)
+ }
+
+ @Test
+ fun logStateChange_bufferHasDeviceTypeTagAndStateNameAndId() {
+ val stateName = "test state name"
+ val id = "test id"
+
+ logger.logStateChange(stateName, id)
+
+ val stringWriter = StringWriter()
+ buffer.dump(PrintWriter(stringWriter), tailLength = 0)
+ val actualString = stringWriter.toString()
+
+ assertThat(actualString).contains(DEVICE_TYPE_TAG)
+ assertThat(actualString).contains(stateName)
+ assertThat(actualString).contains(id)
+ }
+
+ @Test
+ fun logChipRemoval_bufferHasDeviceTypeAndReason() {
+ val reason = "test reason"
+ logger.logChipRemoval(reason)
+
+ val stringWriter = StringWriter()
+ buffer.dump(PrintWriter(stringWriter), tailLength = 0)
+ val actualString = stringWriter.toString()
+
+ assertThat(actualString).contains(DEVICE_TYPE_TAG)
+ assertThat(actualString).contains(reason)
+ }
+}
+
+private const val DEVICE_TYPE_TAG = "TEST TYPE"
diff --git a/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/receiver/MediaTttChipControllerReceiverTest.kt b/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/receiver/MediaTttChipControllerReceiverTest.kt
index 86d4c1b..56f4589 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/receiver/MediaTttChipControllerReceiverTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/receiver/MediaTttChipControllerReceiverTest.kt
@@ -31,6 +31,7 @@
import androidx.test.filters.SmallTest
import com.android.systemui.R
import com.android.systemui.SysuiTestCase
+import com.android.systemui.media.taptotransfer.common.MediaTttLogger
import com.android.systemui.statusbar.CommandQueue
import com.android.systemui.statusbar.gesture.TapGestureDetector
import com.android.systemui.util.concurrency.FakeExecutor
@@ -60,6 +61,8 @@
@Mock
private lateinit var applicationInfo: ApplicationInfo
@Mock
+ private lateinit var logger: MediaTttLogger
+ @Mock
private lateinit var windowManager: WindowManager
@Mock
private lateinit var viewUtil: ViewUtil
@@ -83,6 +86,7 @@
controllerReceiver = MediaTttChipControllerReceiver(
commandQueue,
context,
+ logger,
windowManager,
viewUtil,
FakeExecutor(FakeSystemClock()),
@@ -142,6 +146,18 @@
}
@Test
+ fun receivesNewStateFromCommandQueue_isLogged() {
+ commandQueueCallback.updateMediaTapToTransferReceiverDisplay(
+ StatusBarManager.MEDIA_TRANSFER_RECEIVER_STATE_CLOSE_TO_SENDER,
+ routeInfo,
+ null,
+ null
+ )
+
+ verify(logger).logStateChange(any(), any())
+ }
+
+ @Test
fun displayChip_nullAppIconDrawable_iconIsFromPackageName() {
val state = ChipStateReceiver(PACKAGE_NAME, appIconDrawable = null, "appName")
diff --git a/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/sender/MediaTttChipControllerSenderTest.kt b/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/sender/MediaTttChipControllerSenderTest.kt
index 88888f0..fd1d76a 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/sender/MediaTttChipControllerSenderTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/sender/MediaTttChipControllerSenderTest.kt
@@ -32,6 +32,7 @@
import com.android.internal.statusbar.IUndoMediaTransferCallback
import com.android.systemui.R
import com.android.systemui.SysuiTestCase
+import com.android.systemui.media.taptotransfer.common.MediaTttLogger
import com.android.systemui.statusbar.CommandQueue
import com.android.systemui.statusbar.gesture.TapGestureDetector
import com.android.systemui.util.concurrency.FakeExecutor
@@ -62,6 +63,8 @@
@Mock
private lateinit var applicationInfo: ApplicationInfo
@Mock
+ private lateinit var logger: MediaTttLogger
+ @Mock
private lateinit var windowManager: WindowManager
@Mock
private lateinit var viewUtil: ViewUtil
@@ -69,6 +72,8 @@
private lateinit var commandQueue: CommandQueue
private lateinit var commandQueueCallback: CommandQueue.Callbacks
private lateinit var fakeAppIconDrawable: Drawable
+ private lateinit var fakeClock: FakeSystemClock
+ private lateinit var fakeExecutor: FakeExecutor
@Before
fun setUp() {
@@ -82,12 +87,16 @@
)).thenReturn(applicationInfo)
context.setMockPackageManager(packageManager)
+ fakeClock = FakeSystemClock()
+ fakeExecutor = FakeExecutor(fakeClock)
+
controllerSender = MediaTttChipControllerSender(
commandQueue,
context,
+ logger,
windowManager,
viewUtil,
- FakeExecutor(FakeSystemClock()),
+ fakeExecutor,
TapGestureDetector(context)
)
@@ -223,6 +232,17 @@
}
@Test
+ fun receivesNewStateFromCommandQueue_isLogged() {
+ commandQueueCallback.updateMediaTapToTransferSenderDisplay(
+ StatusBarManager.MEDIA_TRANSFER_SENDER_STATE_ALMOST_CLOSE_TO_START_CAST,
+ routeInfo,
+ null
+ )
+
+ verify(logger).logStateChange(any(), any())
+ }
+
+ @Test
fun almostCloseToStartCast_appIcon_deviceName_noLoadingIcon_noUndo_noFailureIcon() {
val state = almostCloseToStartCast()
controllerSender.displayChip(state)
@@ -460,6 +480,52 @@
assertThat(getChipView().getFailureIcon().visibility).isEqualTo(View.VISIBLE)
}
+ @Test
+ fun transferToReceiverTriggeredThenRemoveChip_chipStillDisplayed() {
+ controllerSender.displayChip(transferToReceiverTriggered())
+ fakeClock.advanceTime(1000L)
+
+ controllerSender.removeChip("fakeRemovalReason")
+ fakeExecutor.runAllReady()
+
+ verify(windowManager, never()).removeView(any())
+ }
+
+ @Test
+ fun transferToReceiverTriggeredThenFarFromReceiver_eventuallyTimesOut() {
+ val state = transferToReceiverTriggered()
+ controllerSender.displayChip(state)
+ fakeClock.advanceTime(1000L)
+ controllerSender.removeChip("fakeRemovalReason")
+
+ fakeClock.advanceTime(state.getTimeoutMs() + 1)
+
+ verify(windowManager).removeView(any())
+ }
+
+ @Test
+ fun transferToThisDeviceTriggeredThenRemoveChip_chipStillDisplayed() {
+ controllerSender.displayChip(transferToThisDeviceTriggered())
+ fakeClock.advanceTime(1000L)
+
+ controllerSender.removeChip("fakeRemovalReason")
+ fakeExecutor.runAllReady()
+
+ verify(windowManager, never()).removeView(any())
+ }
+
+ @Test
+ fun transferToThisDeviceTriggeredThenFarFromReceiver_eventuallyTimesOut() {
+ val state = transferToThisDeviceTriggered()
+ controllerSender.displayChip(state)
+ fakeClock.advanceTime(1000L)
+ controllerSender.removeChip("fakeRemovalReason")
+
+ fakeClock.advanceTime(state.getTimeoutMs() + 1)
+
+ verify(windowManager).removeView(any())
+ }
+
private fun LinearLayout.getAppIconView() = this.requireViewById<ImageView>(R.id.app_icon)
private fun LinearLayout.getChipText(): String =
diff --git a/packages/SystemUI/tests/src/com/android/systemui/power/PowerUITest.java b/packages/SystemUI/tests/src/com/android/systemui/power/PowerUITest.java
index 373770e..91f8a40 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/power/PowerUITest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/power/PowerUITest.java
@@ -430,12 +430,6 @@
state.mIsPowerSaver = true;
shouldShow = mPowerUI.shouldShowHybridWarning(state.get());
assertThat(shouldShow).isFalse();
-
- state.mIsPowerSaver = false;
- // if disabled we should not show the low warning.
- state.mIsLowLevelWarningEnabled = false;
- shouldShow = mPowerUI.shouldShowHybridWarning(state.get());
- assertThat(shouldShow).isFalse();
}
@Test
diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/external/TileLifecycleManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/qs/external/TileLifecycleManagerTest.java
index b559d18..04b50d8 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/qs/external/TileLifecycleManagerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/qs/external/TileLifecycleManagerTest.java
@@ -23,6 +23,7 @@
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyInt;
import static org.mockito.Mockito.anyString;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -34,6 +35,7 @@
import android.content.ContextWrapper;
import android.content.Intent;
import android.content.IntentFilter;
+import android.content.ServiceConnection;
import android.content.pm.PackageInfo;
import android.content.pm.ServiceInfo;
import android.net.Uri;
@@ -56,7 +58,7 @@
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.Mockito;
+import org.mockito.ArgumentCaptor;
@SmallTest
@RunWith(AndroidJUnit4.class)
@@ -64,10 +66,10 @@
private static final int TEST_FAIL_TIMEOUT = 5000;
private final PackageManagerAdapter mMockPackageManagerAdapter =
- Mockito.mock(PackageManagerAdapter.class);
+ mock(PackageManagerAdapter.class);
private final BroadcastDispatcher mMockBroadcastDispatcher =
- Mockito.mock(BroadcastDispatcher.class);
- private final IQSTileService.Stub mMockTileService = Mockito.mock(IQSTileService.Stub.class);
+ mock(BroadcastDispatcher.class);
+ private final IQSTileService.Stub mMockTileService = mock(IQSTileService.Stub.class);
private ComponentName mTileServiceComponentName;
private Intent mTileServiceIntent;
private UserHandle mUser;
@@ -95,7 +97,7 @@
mThread.start();
mHandler = Handler.createAsync(mThread.getLooper());
mStateManager = new TileLifecycleManager(mHandler, mWrappedContext,
- Mockito.mock(IQSService.class),
+ mock(IQSService.class),
mMockPackageManagerAdapter,
mMockBroadcastDispatcher,
mTileServiceIntent,
@@ -269,6 +271,25 @@
assertTrue(mStateManager.isToggleableTile());
}
+ @Test
+ public void testFalseBindCallsUnbind() {
+ Context falseContext = mock(Context.class);
+ when(falseContext.bindServiceAsUser(any(), any(), anyInt(), any())).thenReturn(false);
+ TileLifecycleManager manager = new TileLifecycleManager(mHandler, falseContext,
+ mock(IQSService.class),
+ mMockPackageManagerAdapter,
+ mMockBroadcastDispatcher,
+ mTileServiceIntent,
+ mUser);
+
+ manager.setBindService(true);
+
+ ArgumentCaptor<ServiceConnection> captor = ArgumentCaptor.forClass(ServiceConnection.class);
+ verify(falseContext).bindServiceAsUser(any(), captor.capture(), anyInt(), any());
+
+ verify(falseContext).unbindService(captor.getValue());
+ }
+
private static class TestContextWrapper extends ContextWrapper {
private IntentFilter mLastIntentFilter;
private int mLastFlag;
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/DozeParametersTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/DozeParametersTest.java
index 5f2bbd3..077b41a 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/DozeParametersTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/DozeParametersTest.java
@@ -126,6 +126,12 @@
setAodEnabledForTest(true);
setShouldControlUnlockedScreenOffForTest(true);
setDisplayNeedsBlankingForTest(false);
+
+ // Default to false here (with one test to make sure that when it returns true, we respect
+ // that). We'll test the specific conditions for this to return true/false in the
+ // UnlockedScreenOffAnimationController's tests.
+ when(mUnlockedScreenOffAnimationController.shouldPlayUnlockedScreenOffAnimation())
+ .thenReturn(false);
}
@Test
@@ -174,9 +180,12 @@
*/
@Test
public void testControlUnlockedScreenOffAnimation_dozeAfterScreenOff_false() {
+ mDozeParameters.mKeyguardVisibilityCallback.onKeyguardVisibilityChanged(true);
+
// If AOD is disabled, we shouldn't want to control screen off. Also, let's double check
// that when that value is updated, we called through to PowerManager.
setAodEnabledForTest(false);
+
assertFalse(mDozeParameters.shouldControlScreenOff());
assertTrue(mPowerManagerDozeAfterScreenOff);
@@ -188,7 +197,6 @@
@Test
public void testControlUnlockedScreenOffAnimationDisabled_dozeAfterScreenOff() {
- setShouldControlUnlockedScreenOffForTest(true);
when(mFeatureFlags.isEnabled(Flags.LOCKSCREEN_ANIMATIONS)).thenReturn(false);
assertFalse(mDozeParameters.shouldControlUnlockedScreenOff());
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/UnlockedScreenOffAnimationControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/UnlockedScreenOffAnimationControllerTest.kt
index 050563a..0936b77 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/UnlockedScreenOffAnimationControllerTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/UnlockedScreenOffAnimationControllerTest.kt
@@ -31,6 +31,7 @@
import com.android.systemui.statusbar.StatusBarStateControllerImpl
import com.android.systemui.statusbar.policy.KeyguardStateController
import com.android.systemui.util.settings.GlobalSettings
+import junit.framework.Assert.assertFalse
import org.junit.After
import org.junit.Before
import org.junit.Test
@@ -133,7 +134,7 @@
*/
@Test
fun testAodUiShownIfNotInteractive() {
- `when`(dozeParameters.shouldControlUnlockedScreenOff()).thenReturn(true)
+ `when`(dozeParameters.canControlUnlockedScreenOff()).thenReturn(true)
`when`(powerManager.isInteractive).thenReturn(false)
val callbackCaptor = ArgumentCaptor.forClass(Runnable::class.java)
@@ -156,7 +157,7 @@
*/
@Test
fun testAodUiNotShownIfInteractive() {
- `when`(dozeParameters.shouldControlUnlockedScreenOff()).thenReturn(true)
+ `when`(dozeParameters.canControlUnlockedScreenOff()).thenReturn(true)
`when`(powerManager.isInteractive).thenReturn(true)
val callbackCaptor = ArgumentCaptor.forClass(Runnable::class.java)
@@ -167,4 +168,13 @@
verify(notificationPanelViewController, never()).showAodUi()
}
+
+ @Test
+ fun testNoAnimationPlaying_dozeParamsCanNotControlScreenOff() {
+ `when`(dozeParameters.canControlUnlockedScreenOff()).thenReturn(false)
+
+ assertFalse(controller.shouldPlayUnlockedScreenOffAnimation())
+ controller.startAnimation()
+ assertFalse(controller.isAnimationPlaying())
+ }
}
\ No newline at end of file
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/LocationControllerImplTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/LocationControllerImplTest.java
index 9f9cb40..12cfb32 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/LocationControllerImplTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/LocationControllerImplTest.java
@@ -14,9 +14,12 @@
package com.android.systemui.statusbar.policy;
+
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -24,6 +27,7 @@
import android.app.AppOpsManager;
import android.content.Intent;
+import android.content.pm.PackageManager;
import android.content.pm.UserInfo;
import android.location.LocationManager;
import android.os.Handler;
@@ -67,6 +71,7 @@
private DeviceConfigProxy mDeviceConfigProxy;
private UiEventLoggerFake mUiEventLogger;
+ @Mock private PackageManager mPackageManager;
@Mock private AppOpsController mAppOpsController;
@Mock private UserTracker mUserTracker;
@Mock private SecureSettings mSecureSettings;
@@ -82,6 +87,7 @@
mUiEventLogger = new UiEventLoggerFake();
mTestableLooper = TestableLooper.get(this);
+
mLocationController = new LocationControllerImpl(mContext,
mAppOpsController,
mDeviceConfigProxy,
@@ -90,7 +96,7 @@
mock(BroadcastDispatcher.class),
mock(BootCompleteCache.class),
mUserTracker,
- mContext.getPackageManager(),
+ mPackageManager,
mUiEventLogger,
mSecureSettings);
@@ -178,6 +184,8 @@
@Test
public void testCallbackNotified_additionalOps() {
+ // Return -1 for non system apps
+ when(mPackageManager.getPermissionFlags(any(), any(), any())).thenReturn(-1);
LocationChangeCallback callback = mock(LocationChangeCallback.class);
mLocationController.addCallback(callback);
mDeviceConfigProxy.setProperty(
@@ -190,10 +198,10 @@
when(mAppOpsController.getActiveAppOps())
.thenReturn(ImmutableList.of(
new AppOpItem(AppOpsManager.OP_FINE_LOCATION, 0,
- "com.google.android.googlequicksearchbox",
+ "com.third.party.app",
System.currentTimeMillis())));
mLocationController.onActiveStateChanged(AppOpsManager.OP_FINE_LOCATION, 0,
- "com.google.android.googlequicksearchbox", true);
+ "ccom.third.party.app", true);
mTestableLooper.processAllMessages();
@@ -201,14 +209,14 @@
when(mAppOpsController.getActiveAppOps()).thenReturn(ImmutableList.of());
mLocationController.onActiveStateChanged(AppOpsManager.OP_FINE_LOCATION, 0,
- "com.google.android.googlequicksearchbox", false);
+ "com.third.party.app", false);
mTestableLooper.processAllMessages();
verify(callback, times(1)).onLocationActiveChanged(false);
when(mAppOpsController.getActiveAppOps()).thenReturn(ImmutableList.of());
mLocationController.onActiveStateChanged(AppOpsManager.OP_MONITOR_HIGH_POWER_LOCATION, 0,
- "com.google.android.googlequicksearchbox", true);
+ "com.third.party.app", true);
mTestableLooper.processAllMessages();
verify(callback, times(1)).onLocationActiveChanged(true);
}
@@ -227,10 +235,10 @@
when(mAppOpsController.getActiveAppOps())
.thenReturn(ImmutableList.of(
new AppOpItem(AppOpsManager.OP_FINE_LOCATION, 0,
- "com.google.android.gms",
+ "com.system.app",
System.currentTimeMillis())));
mLocationController.onActiveStateChanged(AppOpsManager.OP_FINE_LOCATION, 0,
- "com.google.android.gms", true);
+ "com.system.app", true);
mTestableLooper.processAllMessages();
@@ -258,10 +266,10 @@
when(mAppOpsController.getActiveAppOps())
.thenReturn(ImmutableList.of(
- new AppOpItem(AppOpsManager.OP_FINE_LOCATION, 0, "com.google.android.gms",
+ new AppOpItem(AppOpsManager.OP_FINE_LOCATION, 0, "com.system.app",
System.currentTimeMillis())));
mLocationController.onActiveStateChanged(AppOpsManager.OP_FINE_LOCATION, 0,
- "com.google.android.gms", true);
+ "com.system.app", true);
mTestableLooper.processAllMessages();
@@ -269,7 +277,7 @@
when(mAppOpsController.getActiveAppOps()).thenReturn(ImmutableList.of());
mLocationController.onActiveStateChanged(AppOpsManager.OP_FINE_LOCATION, 0,
- "com.google.android.gms", false);
+ "com.system.app", false);
mTestableLooper.processAllMessages();
verify(callback, times(1)).onLocationActiveChanged(false);
@@ -277,7 +285,7 @@
when(mSecureSettings.getInt(Settings.Secure.LOCATION_SHOW_SYSTEM_OPS, 0))
.thenReturn(0);
mLocationController.onActiveStateChanged(AppOpsManager.OP_FINE_LOCATION, 0,
- "com.google.android.gms", true);
+ "com.system.app", true);
mTestableLooper.processAllMessages();
@@ -287,6 +295,11 @@
@Test
public void testCallbackNotified_verifyMetrics() {
+ // Return -1 for non system apps and 0 for system apps.
+ when(mPackageManager.getPermissionFlags(any(),
+ eq("com.system.app"), any())).thenReturn(0);
+ when(mPackageManager.getPermissionFlags(any(),
+ eq("com.third.party.app"), any())).thenReturn(-1);
LocationChangeCallback callback = mock(LocationChangeCallback.class);
mLocationController.addCallback(callback);
mDeviceConfigProxy.setProperty(
@@ -298,16 +311,16 @@
when(mAppOpsController.getActiveAppOps())
.thenReturn(ImmutableList.of(
- new AppOpItem(AppOpsManager.OP_FINE_LOCATION, 0, "com.google.android.gms",
+ new AppOpItem(AppOpsManager.OP_FINE_LOCATION, 0, "com.system.app",
System.currentTimeMillis()),
new AppOpItem(AppOpsManager.OP_COARSE_LOCATION, 0,
- "com.google.android.googlequicksearchbox",
+ "com.third.party.app",
System.currentTimeMillis()),
new AppOpItem(AppOpsManager.OP_MONITOR_HIGH_POWER_LOCATION, 0,
- "com.google.android.apps.maps",
+ "com.another.developer.app",
System.currentTimeMillis())));
mLocationController.onActiveStateChanged(AppOpsManager.OP_FINE_LOCATION, 0,
- "com.google.android.gms", true);
+ "com.system.app", true);
mTestableLooper.processAllMessages();
@@ -328,7 +341,7 @@
when(mAppOpsController.getActiveAppOps()).thenReturn(ImmutableList.of());
mLocationController.onActiveStateChanged(AppOpsManager.OP_FINE_LOCATION, 0,
- "com.google.android.gms", false);
+ "com.system.app", false);
mTestableLooper.processAllMessages();
verify(callback, times(1)).onLocationActiveChanged(false);
@@ -354,4 +367,4 @@
// No new callbacks
verify(callback).onLocationSettingsChanged(anyBoolean());
}
-}
+}
\ No newline at end of file
diff --git a/services/api/current.txt b/services/api/current.txt
index e46c972..440f66a 100644
--- a/services/api/current.txt
+++ b/services/api/current.txt
@@ -38,7 +38,7 @@
package com.android.server.am {
public interface ActivityManagerLocal {
- method public boolean bindSupplementalProcessService(@NonNull android.content.Intent, @NonNull android.content.ServiceConnection, int, @NonNull String, int) throws android.os.RemoteException;
+ method public boolean bindSdkSandboxService(@NonNull android.content.Intent, @NonNull android.content.ServiceConnection, int, @NonNull String, int) throws android.os.RemoteException;
method public boolean canStartForegroundService(int, int, @NonNull String);
}
diff --git a/services/backup/java/com/android/server/backup/restore/FullRestoreEngine.java b/services/backup/java/com/android/server/backup/restore/FullRestoreEngine.java
index c42055c..76df8b9 100644
--- a/services/backup/java/com/android/server/backup/restore/FullRestoreEngine.java
+++ b/services/backup/java/com/android/server/backup/restore/FullRestoreEngine.java
@@ -24,10 +24,8 @@
import static com.android.server.backup.UserBackupManagerService.SHARED_BACKUP_AGENT_PACKAGE;
import static com.android.server.backup.internal.BackupHandler.MSG_RESTORE_OPERATION_TIMEOUT;
-import android.annotation.NonNull;
import android.app.ApplicationThreadConstants;
import android.app.IBackupAgent;
-import android.app.backup.BackupAgent;
import android.app.backup.BackupManager;
import android.app.backup.FullBackup;
import android.app.backup.IBackupManagerMonitor;
@@ -40,12 +38,10 @@
import android.os.ParcelFileDescriptor;
import android.os.RemoteException;
import android.provider.Settings;
-import android.system.OsConstants;
import android.text.TextUtils;
import android.util.Slog;
import com.android.internal.annotations.GuardedBy;
-import com.android.internal.annotations.VisibleForTesting;
import com.android.server.LocalServices;
import com.android.server.backup.BackupAgentTimeoutParameters;
import com.android.server.backup.BackupRestoreTask;
@@ -61,7 +57,6 @@
import com.android.server.backup.utils.RestoreUtils;
import com.android.server.backup.utils.TarBackupReader;
-import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -139,7 +134,6 @@
@GuardedBy("mPipesLock")
private boolean mPipesClosed;
private final BackupEligibilityRules mBackupEligibilityRules;
- private FileMetadata mReadOnlyParent = null;
public FullRestoreEngine(
UserBackupManagerService backupManagerService, OperationStorage operationStorage,
@@ -164,21 +158,6 @@
mBackupEligibilityRules = backupEligibilityRules;
}
- @VisibleForTesting
- FullRestoreEngine() {
- mIsAdbRestore = false;
- mAllowApks = false;
- mEphemeralOpToken = 0;
- mUserId = 0;
- mBackupEligibilityRules = null;
- mAgentTimeoutParameters = null;
- mBuffer = null;
- mBackupManagerService = null;
- mMonitor = null;
- mMonitorTask = null;
- mOnlyPackage = null;
- }
-
public IBackupAgent getAgent() {
return mAgent;
}
@@ -418,11 +397,6 @@
okay = false;
}
- if (shouldSkipReadOnlyDir(info)) {
- // b/194894879: We don't support restore of read-only dirs.
- okay = false;
- }
-
// At this point we have an agent ready to handle the full
// restore data as well as a pipe for sending data to
// that agent. Tell the agent to start reading from the
@@ -599,45 +573,6 @@
return (info != null);
}
- boolean shouldSkipReadOnlyDir(FileMetadata info) {
- if (isValidParent(mReadOnlyParent, info)) {
- // This file has a read-only parent directory, we shouldn't
- // restore it.
- return true;
- } else {
- // We're now in a different branch of the file tree, update the parent
- // value.
- if (isReadOnlyDir(info)) {
- // Current directory is read-only. Remember it so that we can skip all
- // of its contents.
- mReadOnlyParent = info;
- Slog.w(TAG, "Skipping restore of " + info.path + " and its contents as "
- + "read-only dirs are currently not supported.");
- return true;
- } else {
- mReadOnlyParent = null;
- }
- }
-
- return false;
- }
-
- private static boolean isValidParent(FileMetadata parentDir, @NonNull FileMetadata childDir) {
- return parentDir != null
- && childDir.packageName.equals(parentDir.packageName)
- && childDir.domain.equals(parentDir.domain)
- && childDir.path.startsWith(getPathWithTrailingSeparator(parentDir.path));
- }
-
- private static String getPathWithTrailingSeparator(String path) {
- return path.endsWith(File.separator) ? path : path + File.separator;
- }
-
- private static boolean isReadOnlyDir(FileMetadata file) {
- // Check if owner has 'write' bit in the file's mode value (see 'man -7 inode' for details).
- return file.type == BackupAgent.TYPE_DIRECTORY && (file.mode & OsConstants.S_IWUSR) == 0;
- }
-
private void setUpPipes() throws IOException {
synchronized (mPipesLock) {
mPipes = ParcelFileDescriptor.createPipe();
diff --git a/services/cloudsearch/java/com/android/server/cloudsearch/CloudSearchManagerService.java b/services/cloudsearch/java/com/android/server/cloudsearch/CloudSearchManagerService.java
index daead0a..b1f572d 100644
--- a/services/cloudsearch/java/com/android/server/cloudsearch/CloudSearchManagerService.java
+++ b/services/cloudsearch/java/com/android/server/cloudsearch/CloudSearchManagerService.java
@@ -43,6 +43,8 @@
import com.android.server.wm.ActivityTaskManagerInternal;
import java.io.FileDescriptor;
+import java.util.ArrayList;
+import java.util.List;
import java.util.function.Consumer;
/**
@@ -62,7 +64,7 @@
public CloudSearchManagerService(Context context) {
super(context, new FrameworkResourcesServiceNameResolver(context,
- R.string.config_defaultCloudSearchService), null,
+ R.array.config_defaultCloudSearchServices, true), null,
PACKAGE_UPDATE_POLICY_NO_REFRESH | PACKAGE_RESTART_POLICY_NO_REFRESH);
mActivityTaskManagerInternal = LocalServices.getService(ActivityTaskManagerInternal.class);
mContext = context;
@@ -70,7 +72,25 @@
@Override
protected CloudSearchPerUserService newServiceLocked(int resolvedUserId, boolean disabled) {
- return new CloudSearchPerUserService(this, mLock, resolvedUserId);
+ return new CloudSearchPerUserService(this, mLock, resolvedUserId, "");
+ }
+
+ @Override
+ protected List<CloudSearchPerUserService> newServiceListLocked(int resolvedUserId,
+ boolean disabled, String[] serviceNames) {
+ if (serviceNames == null) {
+ return new ArrayList<>();
+ }
+ List<CloudSearchPerUserService> serviceList =
+ new ArrayList<>(serviceNames.length);
+ for (int i = 0; i < serviceNames.length; i++) {
+ if (serviceNames[i] == null) {
+ continue;
+ }
+ serviceList.add(new CloudSearchPerUserService(this, mLock, resolvedUserId,
+ serviceNames[i]));
+ }
+ return serviceList;
}
@Override
@@ -111,19 +131,28 @@
@NonNull ICloudSearchManagerCallback callBack) {
searchRequest.setSource(
mContext.getPackageManager().getNameForUid(Binder.getCallingUid()));
- runForUserLocked("search", searchRequest.getRequestId(), (service) ->
- service.onSearchLocked(searchRequest, callBack));
+ runForUser("search", (service) -> {
+ synchronized (service.mLock) {
+ service.onSearchLocked(searchRequest, callBack);
+ }
+ });
}
@Override
public void returnResults(IBinder token, String requestId, SearchResponse response) {
- runForUserLocked("returnResults", requestId, (service) ->
- service.onReturnResultsLocked(token, requestId, response));
+ runForUser("returnResults", (service) -> {
+ synchronized (service.mLock) {
+ service.onReturnResultsLocked(token, requestId, response);
+ }
+ });
}
public void destroy(@NonNull SearchRequest searchRequest) {
- runForUserLocked("destroyCloudSearchSession", searchRequest.getRequestId(),
- (service) -> service.onDestroyLocked(searchRequest.getRequestId()));
+ runForUser("destroyCloudSearchSession", (service) -> {
+ synchronized (service.mLock) {
+ service.onDestroyLocked(searchRequest.getRequestId());
+ }
+ });
}
public void onShellCommand(@Nullable FileDescriptor in, @Nullable FileDescriptor out,
@@ -134,8 +163,7 @@
.exec(this, in, out, err, args, callback, resultReceiver);
}
- private void runForUserLocked(@NonNull final String func,
- @NonNull final String requestId,
+ private void runForUser(@NonNull final String func,
@NonNull final Consumer<CloudSearchPerUserService> c) {
ActivityManagerInternal am = LocalServices.getService(ActivityManagerInternal.class);
final int userId = am.handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(),
@@ -143,7 +171,7 @@
null, null);
if (DEBUG) {
- Slog.d(TAG, "runForUserLocked:" + func + " from pid=" + Binder.getCallingPid()
+ Slog.d(TAG, "runForUser:" + func + " from pid=" + Binder.getCallingPid()
+ ", uid=" + Binder.getCallingUid());
}
Context ctx = getContext();
@@ -160,8 +188,11 @@
final long origId = Binder.clearCallingIdentity();
try {
synchronized (mLock) {
- final CloudSearchPerUserService service = getServiceForUserLocked(userId);
- c.accept(service);
+ final List<CloudSearchPerUserService> services =
+ getServiceListForUserLocked(userId);
+ for (int i = 0; i < services.size(); i++) {
+ c.accept(services.get(i));
+ }
}
} finally {
Binder.restoreCallingIdentity(origId);
diff --git a/services/cloudsearch/java/com/android/server/cloudsearch/CloudSearchManagerServiceShellCommand.java b/services/cloudsearch/java/com/android/server/cloudsearch/CloudSearchManagerServiceShellCommand.java
index 51f5fd9..c64982d 100644
--- a/services/cloudsearch/java/com/android/server/cloudsearch/CloudSearchManagerServiceShellCommand.java
+++ b/services/cloudsearch/java/com/android/server/cloudsearch/CloudSearchManagerServiceShellCommand.java
@@ -54,7 +54,12 @@
return 0;
}
final int duration = Integer.parseInt(getNextArgRequired());
- mService.setTemporaryService(userId, serviceName, duration);
+ String[] services = serviceName.split(";");
+ if (services.length == 0) {
+ return 0;
+ } else {
+ mService.setTemporaryServices(userId, services, duration);
+ }
pw.println("CloudSearchService temporarily set to " + serviceName
+ " for " + duration + "ms");
break;
diff --git a/services/cloudsearch/java/com/android/server/cloudsearch/CloudSearchPerUserService.java b/services/cloudsearch/java/com/android/server/cloudsearch/CloudSearchPerUserService.java
index 32d66af..116c739 100644
--- a/services/cloudsearch/java/com/android/server/cloudsearch/CloudSearchPerUserService.java
+++ b/services/cloudsearch/java/com/android/server/cloudsearch/CloudSearchPerUserService.java
@@ -49,6 +49,8 @@
@GuardedBy("mLock")
private final CircularQueue<String, CloudSearchCallbackInfo> mCallbackQueue =
new CircularQueue<>(QUEUE_SIZE);
+ private final String mServiceName;
+ private final ComponentName mRemoteComponentName;
@Nullable
@GuardedBy("mLock")
private RemoteCloudSearchService mRemoteService;
@@ -60,8 +62,10 @@
private boolean mZombie;
protected CloudSearchPerUserService(CloudSearchManagerService master,
- Object lock, int userId) {
+ Object lock, int userId, String serviceName) {
super(master, lock, userId);
+ mServiceName = serviceName;
+ mRemoteComponentName = ComponentName.unflattenFromString(mServiceName);
}
@Override // from PerUserSystemService
@@ -108,7 +112,7 @@
? searchRequest.getSearchConstraints().getString(
SearchRequest.CONSTRAINT_SEARCH_PROVIDER_FILTER) : "";
- String remoteServicePackageName = getServiceComponentName().getPackageName();
+ String remoteServicePackageName = mRemoteComponentName.getPackageName();
// By default, all providers are marked as wanted.
boolean wantedProvider = true;
if (filterList.length() > 0) {
@@ -150,11 +154,19 @@
/**
* Used to return results back to the clients.
*/
+ @GuardedBy("mLock")
public void onReturnResultsLocked(@NonNull IBinder token,
@NonNull String requestId,
@NonNull SearchResponse response) {
+ if (mRemoteService == null) {
+ return;
+ }
+ ICloudSearchService serviceInterface = mRemoteService.getServiceInterface();
+ if (serviceInterface == null || token != serviceInterface.asBinder()) {
+ return;
+ }
if (mCallbackQueue.containsKey(requestId)) {
- response.setSource(mRemoteService.getComponentName().getPackageName());
+ response.setSource(mServiceName);
final CloudSearchCallbackInfo sessionInfo = mCallbackQueue.getElement(requestId);
try {
if (response.getStatusCode() == SearchResponse.SEARCH_STATUS_OK) {
@@ -163,6 +175,10 @@
sessionInfo.mCallback.onSearchFailed(response);
}
} catch (RemoteException e) {
+ if (mMaster.debug) {
+ Slog.e(TAG, "Exception in posting results");
+ e.printStackTrace();
+ }
onDestroyLocked(requestId);
}
}
@@ -297,7 +313,7 @@
@Nullable
private RemoteCloudSearchService getRemoteServiceLocked() {
if (mRemoteService == null) {
- final String serviceName = getComponentNameLocked();
+ final String serviceName = getComponentNameForMultipleLocked(mServiceName);
if (serviceName == null) {
if (mMaster.verbose) {
Slog.v(TAG, "getRemoteServiceLocked(): not set");
diff --git a/services/core/Android.bp b/services/core/Android.bp
index a2b289c..0241c1e 100644
--- a/services/core/Android.bp
+++ b/services/core/Android.bp
@@ -133,7 +133,7 @@
"app-compat-annotations",
"framework-tethering.stubs.module_lib",
"service-permission.stubs.system_server",
- "service-supplementalprocess.stubs.system_server",
+ "service-sdksandbox.stubs.system_server",
],
required: [
diff --git a/services/core/java/com/android/server/NetworkTimeUpdateService.java b/services/core/java/com/android/server/NetworkTimeUpdateService.java
index a0f239d..fcde533 100644
--- a/services/core/java/com/android/server/NetworkTimeUpdateService.java
+++ b/services/core/java/com/android/server/NetworkTimeUpdateService.java
@@ -171,7 +171,9 @@
>= mPollingIntervalMs) {
if (DBG) Log.d(TAG, "Stale NTP fix; forcing refresh");
boolean isSuccessful = mTime.forceRefresh();
- if (!isSuccessful) {
+ if (isSuccessful) {
+ mTryAgainCounter = 0;
+ } else {
String logMsg = "forceRefresh() returned false: cachedNtpResult=" + cachedNtpResult
+ ", currentElapsedRealtimeMillis=" + currentElapsedRealtimeMillis;
@@ -188,7 +190,8 @@
&& cachedNtpResult.getAgeMillis(currentElapsedRealtimeMillis)
< mPollingIntervalMs) {
// Obtained fresh fix; schedule next normal update
- resetAlarm(mPollingIntervalMs);
+ resetAlarm(mPollingIntervalMs
+ - cachedNtpResult.getAgeMillis(currentElapsedRealtimeMillis));
// Suggest the time to the time detector. It may choose use it to set the system clock.
TimestampedValue<Long> timeSignal = new TimestampedValue<>(
diff --git a/services/core/java/com/android/server/OWNERS b/services/core/java/com/android/server/OWNERS
index 4129feb..6ff8e36 100644
--- a/services/core/java/com/android/server/OWNERS
+++ b/services/core/java/com/android/server/OWNERS
@@ -21,14 +21,13 @@
per-file *Battery* = file:/BATTERY_STATS_OWNERS
per-file *BinaryTransparency* = file:/core/java/android/transparency/OWNERS
per-file *Binder* = file:/core/java/com/android/internal/os/BINDER_OWNERS
-per-file *Bluetooth* = file:/core/java/android/bluetooth/OWNERS
per-file *Gnss* = file:/services/core/java/com/android/server/location/OWNERS
per-file **IpSec* = file:/services/core/java/com/android/server/net/OWNERS
per-file **IpSec* = file:/services/core/java/com/android/server/vcn/OWNERS
per-file *Location* = file:/services/core/java/com/android/server/location/OWNERS
per-file *Network* = file:/services/core/java/com/android/server/net/OWNERS
per-file *Storage* = file:/core/java/android/os/storage/OWNERS
-per-file *TimeUpdate* = file:/core/java/android/app/timezone/OWNERS
+per-file *TimeUpdate* = file:/services/core/java/com/android/server/timezonedetector/OWNERS
per-file DynamicSystemService.java = file:/packages/DynamicSystemInstallationService/OWNERS
per-file GestureLauncherService.java = file:platform/packages/apps/EmergencyInfo:/OWNERS
per-file MmsServiceBroker.java = file:/telephony/OWNERS
diff --git a/services/core/java/com/android/server/StorageManagerService.java b/services/core/java/com/android/server/StorageManagerService.java
index c194527..d4764a6 100644
--- a/services/core/java/com/android/server/StorageManagerService.java
+++ b/services/core/java/com/android/server/StorageManagerService.java
@@ -4747,7 +4747,7 @@
private int getMountModeInternal(int uid, String packageName) {
try {
// Get some easy cases out of the way first
- if (Process.isIsolated(uid) || Process.isSupplemental(uid)) {
+ if (Process.isIsolated(uid) || Process.isSdkSandboxUid(uid)) {
return StorageManager.MOUNT_MODE_EXTERNAL_NONE;
}
diff --git a/services/core/java/com/android/server/am/ActiveServices.java b/services/core/java/com/android/server/am/ActiveServices.java
index 092172a..38f6e6d 100644
--- a/services/core/java/com/android/server/am/ActiveServices.java
+++ b/services/core/java/com/android/server/am/ActiveServices.java
@@ -2721,7 +2721,7 @@
int bindServiceLocked(IApplicationThread caller, IBinder token, Intent service,
String resolvedType, final IServiceConnection connection, int flags,
- String instanceName, boolean isSupplementalProcessService, int supplementedAppUid,
+ String instanceName, boolean isSdkSandboxService, int sdkSandboxClientAppUid,
String callingPackage, final int userId)
throws TransactionTooLargeException {
if (DEBUG_SERVICE) Slog.v(TAG_SERVICE, "bindService: " + service
@@ -2807,7 +2807,7 @@
final boolean allowInstant = (flags & Context.BIND_ALLOW_INSTANT) != 0;
ServiceLookupResult res = retrieveServiceLocked(service, instanceName,
- isSupplementalProcessService, supplementedAppUid, resolvedType, callingPackage,
+ isSdkSandboxService, sdkSandboxClientAppUid, resolvedType, callingPackage,
callingPid, callingUid, userId, true, callerFg, isBindExternal, allowInstant);
if (res == null) {
return 0;
@@ -3234,13 +3234,13 @@
}
private ServiceLookupResult retrieveServiceLocked(Intent service,
- String instanceName, boolean isSupplementalProcessService, int supplementedAppUid,
+ String instanceName, boolean isSdkSandboxService, int sdkSandboxClientAppUid,
String resolvedType,
String callingPackage, int callingPid, int callingUid, int userId,
boolean createIfNeeded, boolean callingFromFg, boolean isBindExternal,
boolean allowInstant) {
- if (isSupplementalProcessService && instanceName == null) {
- throw new IllegalArgumentException("No instanceName provided for supplemental process");
+ if (isSdkSandboxService && instanceName == null) {
+ throw new IllegalArgumentException("No instanceName provided for sdk sandbox process");
}
ServiceRecord r = null;
@@ -3319,13 +3319,13 @@
}
if (instanceName != null
&& (sInfo.flags & ServiceInfo.FLAG_ISOLATED_PROCESS) == 0
- && !isSupplementalProcessService) {
+ && !isSdkSandboxService) {
throw new IllegalArgumentException("Can't use instance name '" + instanceName
- + "' with non-isolated non-supplemental service '" + sInfo.name + "'");
+ + "' with non-isolated non-sdk sandbox service '" + sInfo.name + "'");
}
- if (isSupplementalProcessService
+ if (isSdkSandboxService
&& (sInfo.flags & ServiceInfo.FLAG_ISOLATED_PROCESS) != 0) {
- throw new IllegalArgumentException("Service cannot be both supplemental and "
+ throw new IllegalArgumentException("Service cannot be both sdk sandbox and "
+ "isolated");
}
@@ -3412,11 +3412,11 @@
final Intent.FilterComparison filter
= new Intent.FilterComparison(service.cloneFilter());
final ServiceRestarter res = new ServiceRestarter();
- String supplementalProcessName = isSupplementalProcessService ? instanceName
+ String sdkSandboxProcessName = isSdkSandboxService ? instanceName
: null;
r = new ServiceRecord(mAm, className, name, definingPackageName,
definingUid, filter, sInfo, callingFromFg, res,
- supplementalProcessName, supplementedAppUid);
+ sdkSandboxProcessName, sdkSandboxClientAppUid);
res.setService(r);
smap.mServicesByInstanceName.put(name, r);
smap.mServicesByIntent.put(filter, r);
@@ -4190,9 +4190,9 @@
if (app == null && !permissionsReviewRequired && !packageFrozen) {
// TODO (chriswailes): Change the Zygote policy flags based on if the launch-for-service
// was initiated from a notification tap or not.
- if (r.supplemental) {
- final int uid = Process.toSupplementalUid(r.supplementedAppUid);
- app = mAm.startSupplementalProcessLocked(procName, r.appInfo, true, intentFlags,
+ if (r.isSdkSandbox) {
+ final int uid = Process.toSdkSandboxUid(r.sdkSandboxClientAppUid);
+ app = mAm.startSdkSandboxProcessLocked(procName, r.appInfo, true, intentFlags,
hostingRecord, ZYGOTE_POLICY_FLAG_EMPTY, uid);
r.isolationHostProc = app;
} else {
diff --git a/services/core/java/com/android/server/am/ActivityManagerLocal.java b/services/core/java/com/android/server/am/ActivityManagerLocal.java
index 535340b..3226a2b 100644
--- a/services/core/java/com/android/server/am/ActivityManagerLocal.java
+++ b/services/core/java/com/android/server/am/ActivityManagerLocal.java
@@ -65,15 +65,15 @@
void tempAllowWhileInUsePermissionInFgs(int uid, long durationMs);
/**
- * Binds to a supplemental process service, creating it if needed. You can through the arguments
+ * Binds to a sdk sandbox service, creating it if needed. You can through the arguments
* here have the system bring up multiple concurrent processes hosting their own instance of
* that service. The {@code processName} you provide here identifies the different instances.
*
- * @param service Identifies the supplemental process service to connect to. The Intent must
+ * @param service Identifies the sdk sandbox process service to connect to. The Intent must
* specify an explicit component name. This value cannot be null.
* @param conn Receives information as the service is started and stopped.
* This must be a valid ServiceConnection object; it must not be null.
- * @param userAppUid Uid of the app for which the supplemental process needs to be spawned.
+ * @param clientAppUid Uid of the app for which the sdk sandbox process needs to be spawned.
* @param processName Unique identifier for the service instance. Each unique name here will
* result in a different service instance being created. Identifiers must only contain
* ASCII letters, digits, underscores, and periods.
@@ -86,7 +86,7 @@
* @see Context#bindService(Intent, ServiceConnection, int)
*/
@SuppressLint("RethrowRemoteException")
- boolean bindSupplementalProcessService(@NonNull Intent service, @NonNull ServiceConnection conn,
- int userAppUid, @NonNull String processName, @Context.BindServiceFlags int flags)
+ boolean bindSdkSandboxService(@NonNull Intent service, @NonNull ServiceConnection conn,
+ int clientAppUid, @NonNull String processName, @Context.BindServiceFlags int flags)
throws RemoteException;
}
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
index 20a8509..3302cfb 100644
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -2789,13 +2789,13 @@
}
@GuardedBy("this")
- final ProcessRecord startSupplementalProcessLocked(String processName,
+ final ProcessRecord startSdkSandboxProcessLocked(String processName,
ApplicationInfo info, boolean knownToBeDead, int intentFlags,
- HostingRecord hostingRecord, int zygotePolicyFlags, int supplementalUid) {
+ HostingRecord hostingRecord, int zygotePolicyFlags, int sdkSandboxUid) {
return mProcessList.startProcessLocked(processName, info, knownToBeDead, intentFlags,
hostingRecord, zygotePolicyFlags, false /* allowWhileBooting */,
false /* isolated */, 0 /* isolatedUid */,
- true /* supplemental */, supplementalUid,
+ true /* isSdkSandbox */, sdkSandboxUid,
null /* ABI override */, null /* entryPoint */,
null /* entryPointArgs */, null /* crashHandler */);
}
@@ -2807,7 +2807,7 @@
boolean isolated) {
return mProcessList.startProcessLocked(processName, info, knownToBeDead, intentFlags,
hostingRecord, zygotePolicyFlags, allowWhileBooting, isolated, 0 /* isolatedUid */,
- false /* supplemental */, 0 /* supplementalUid */,
+ false /* isSdkSandbox */, 0 /* sdkSandboxClientdAppUid */,
null /* ABI override */, null /* entryPoint */,
null /* entryPointArgs */, null /* crashHandler */);
}
@@ -12396,7 +12396,7 @@
private int bindServiceInstance(IApplicationThread caller, IBinder token, Intent service,
String resolvedType, IServiceConnection connection, int flags, String instanceName,
- boolean isSupplementalProcessService, int supplementedAppUid, String callingPackage,
+ boolean isSdkSandboxService, int sdkSandboxClientdAppUid, String callingPackage,
int userId)
throws TransactionTooLargeException {
enforceNotIsolatedCaller("bindService");
@@ -12410,7 +12410,7 @@
throw new IllegalArgumentException("callingPackage cannot be null");
}
- if (isSupplementalProcessService && instanceName == null) {
+ if (isSdkSandboxService && instanceName == null) {
throw new IllegalArgumentException("No instance name provided for isolated process");
}
@@ -12428,7 +12428,7 @@
synchronized(this) {
return mServices.bindServiceLocked(caller, token, service, resolvedType, connection,
- flags, instanceName, isSupplementalProcessService, supplementedAppUid,
+ flags, instanceName, isSdkSandboxService, sdkSandboxClientdAppUid,
callingPackage, userId);
}
}
@@ -16006,7 +16006,7 @@
}
@Override
- public boolean bindSupplementalProcessService(Intent service, ServiceConnection conn,
+ public boolean bindSdkSandboxService(Intent service, ServiceConnection conn,
int userAppUid, String processName, int flags) throws RemoteException {
if (service == null) {
throw new IllegalArgumentException("intent is null");
diff --git a/services/core/java/com/android/server/am/AppRestrictionController.java b/services/core/java/com/android/server/am/AppRestrictionController.java
index 561c10b9..d07590f 100644
--- a/services/core/java/com/android/server/am/AppRestrictionController.java
+++ b/services/core/java/com/android/server/am/AppRestrictionController.java
@@ -398,23 +398,24 @@
return sb.toString();
}
- @GuardedBy("mSettingsLock")
void dump(PrintWriter pw, @ElapsedRealtimeLong long nowElapsed) {
- pw.print(toString());
- if (mLastRestrictionLevel != RESTRICTION_LEVEL_UNKNOWN) {
- pw.print('/');
- pw.print(ActivityManager.restrictionLevelToName(mLastRestrictionLevel));
- }
- pw.print(" levelChange=");
- TimeUtils.formatDuration(mLevelChangeTimeElapsed - nowElapsed, pw);
- if (mLastNotificationShownTimeElapsed != null) {
- for (int i = 0; i < mLastNotificationShownTimeElapsed.length; i++) {
- if (mLastNotificationShownTimeElapsed[i] > 0) {
- pw.print(" lastNoti(");
- pw.print(mNotificationHelper.notificationTypeToString(i));
- pw.print(")=");
- TimeUtils.formatDuration(
- mLastNotificationShownTimeElapsed[i] - nowElapsed, pw);
+ synchronized (mSettingsLock) {
+ pw.print(toString());
+ if (mLastRestrictionLevel != RESTRICTION_LEVEL_UNKNOWN) {
+ pw.print('/');
+ pw.print(ActivityManager.restrictionLevelToName(mLastRestrictionLevel));
+ }
+ pw.print(" levelChange=");
+ TimeUtils.formatDuration(mLevelChangeTimeElapsed - nowElapsed, pw);
+ if (mLastNotificationShownTimeElapsed != null) {
+ for (int i = 0; i < mLastNotificationShownTimeElapsed.length; i++) {
+ if (mLastNotificationShownTimeElapsed[i] > 0) {
+ pw.print(" lastNoti(");
+ pw.print(mNotificationHelper.notificationTypeToString(i));
+ pw.print(")=");
+ TimeUtils.formatDuration(
+ mLastNotificationShownTimeElapsed[i] - nowElapsed, pw);
+ }
}
}
}
@@ -612,10 +613,11 @@
}
}
- @GuardedBy("mSettingsLock")
- void dumpLocked(PrintWriter pw, String prefix) {
+ void dump(PrintWriter pw, String prefix) {
final ArrayList<PkgSettings> settings = new ArrayList<>();
- mRestrictionLevels.forEach(setting -> settings.add(setting));
+ synchronized (mSettingsLock) {
+ mRestrictionLevels.forEach(setting -> settings.add(setting));
+ }
Collections.sort(settings, Comparator.comparingInt(PkgSettings::getUid));
final long nowElapsed = SystemClock.elapsedRealtime();
for (int i = 0, size = settings.size(); i < size; i++) {
@@ -1322,11 +1324,7 @@
prefix = " " + prefix;
pw.print(prefix);
pw.println("BACKGROUND RESTRICTION LEVEL SETTINGS");
- /*
- synchronized (mSettingsLock) {
- mRestrictionSettings.dumpLocked(pw, " " + prefix);
- }
- */
+ mRestrictionSettings.dump(pw, " " + prefix);
mConstantsObserver.dump(pw, " " + prefix);
for (int i = 0, size = mAppStateTrackers.size(); i < size; i++) {
pw.println();
diff --git a/services/core/java/com/android/server/am/ProcessList.java b/services/core/java/com/android/server/am/ProcessList.java
index 763bbee..41cd61d 100644
--- a/services/core/java/com/android/server/am/ProcessList.java
+++ b/services/core/java/com/android/server/am/ProcessList.java
@@ -2532,7 +2532,7 @@
ProcessRecord startProcessLocked(String processName, ApplicationInfo info,
boolean knownToBeDead, int intentFlags, HostingRecord hostingRecord,
int zygotePolicyFlags, boolean allowWhileBooting, boolean isolated, int isolatedUid,
- boolean supplemental, int supplementalUid,
+ boolean isSdkSandbox, int sdkSandboxUid,
String abiOverride, String entryPoint, String[] entryPointArgs, Runnable crashHandler) {
long startTime = SystemClock.uptimeMillis();
ProcessRecord app;
@@ -2626,8 +2626,8 @@
if (app == null) {
checkSlow(startTime, "startProcess: creating new process record");
- app = newProcessRecordLocked(info, processName, isolated, isolatedUid, supplemental,
- supplementalUid, hostingRecord);
+ app = newProcessRecordLocked(info, processName, isolated, isolatedUid, isSdkSandbox,
+ sdkSandboxUid, hostingRecord);
if (app == null) {
Slog.w(TAG, "Failed making new process record for "
+ processName + "/" + info.uid + " isolated=" + isolated);
@@ -3122,13 +3122,13 @@
@GuardedBy("mService")
ProcessRecord newProcessRecordLocked(ApplicationInfo info, String customProcess,
- boolean isolated, int isolatedUid, boolean supplemental, int supplementalUid,
+ boolean isolated, int isolatedUid, boolean isSdkSandbox, int sdkSandboxUid,
HostingRecord hostingRecord) {
String proc = customProcess != null ? customProcess : info.processName;
final int userId = UserHandle.getUserId(info.uid);
int uid = info.uid;
- if (supplemental) {
- uid = supplementalUid;
+ if (isSdkSandbox) {
+ uid = sdkSandboxUid;
}
if (isolated) {
if (isolatedUid == 0) {
diff --git a/services/core/java/com/android/server/am/ServiceRecord.java b/services/core/java/com/android/server/am/ServiceRecord.java
index bf2876f..c53d4d6 100644
--- a/services/core/java/com/android/server/am/ServiceRecord.java
+++ b/services/core/java/com/android/server/am/ServiceRecord.java
@@ -94,8 +94,8 @@
final boolean exported; // from ServiceInfo.exported
final Runnable restarter; // used to schedule retries of starting the service
final long createRealTime; // when this service was created
- final boolean supplemental; // whether this is a supplemental service
- final int supplementedAppUid; // the app uid for which this supplemental service is running
+ final boolean isSdkSandbox; // whether this is a sdk sandbox service
+ final int sdkSandboxClientAppUid; // the app uid for which this sdk sandbox service is running
final ArrayMap<Intent.FilterComparison, IntentBindRecord> bindings
= new ArrayMap<Intent.FilterComparison, IntentBindRecord>();
// All active bindings to the service.
@@ -105,7 +105,7 @@
ProcessRecord app; // where this service is running or null.
ProcessRecord isolationHostProc; // process which we've started for this service (used for
- // isolated and supplemental processes)
+ // isolated and sdk sandbox processes)
ServiceState tracker; // tracking service execution, may be null
ServiceState restartTracker; // tracking service restart
boolean allowlistManager; // any bindings to this service have BIND_ALLOW_WHITELIST_MANAGEMENT?
@@ -579,7 +579,7 @@
ServiceRecord(ActivityManagerService ams, ComponentName name,
ComponentName instanceName, String definingPackageName, int definingUid,
Intent.FilterComparison intent, ServiceInfo sInfo, boolean callerIsFg,
- Runnable restarter, String supplementalProcessName, int supplementedAppUid) {
+ Runnable restarter, String sdkSandboxProcessName, int sdkSandboxClientAppUid) {
this.ams = ams;
this.name = name;
this.instanceName = instanceName;
@@ -590,12 +590,12 @@
serviceInfo = sInfo;
appInfo = sInfo.applicationInfo;
packageName = sInfo.applicationInfo.packageName;
- supplemental = supplementalProcessName != null;
- this.supplementedAppUid = supplementedAppUid;
+ isSdkSandbox = sdkSandboxProcessName != null;
+ this.sdkSandboxClientAppUid = sdkSandboxClientAppUid;
if ((sInfo.flags & ServiceInfo.FLAG_ISOLATED_PROCESS) != 0) {
processName = sInfo.processName + ":" + instanceName.getClassName();
- } else if (supplementalProcessName != null) {
- processName = supplementalProcessName;
+ } else if (sdkSandboxProcessName != null) {
+ processName = sdkSandboxProcessName;
} else {
processName = sInfo.processName;
}
diff --git a/services/core/java/com/android/server/am/UserController.java b/services/core/java/com/android/server/am/UserController.java
index b6801fb..1095cf0 100644
--- a/services/core/java/com/android/server/am/UserController.java
+++ b/services/core/java/com/android/server/am/UserController.java
@@ -2613,7 +2613,7 @@
if (getStartedUserState(userId) == null) {
return false;
}
- if (!getUserInfo(userId).isManagedProfile()) {
+ if (!mInjector.getUserManager().isCredentialSharedWithParent(userId)) {
return false;
}
if (mLockPatternUtils.isSeparateProfileChallengeEnabled(userId)) {
diff --git a/services/core/java/com/android/server/appop/AppOpsService.java b/services/core/java/com/android/server/appop/AppOpsService.java
index e2d00f7..ef7c93d 100644
--- a/services/core/java/com/android/server/appop/AppOpsService.java
+++ b/services/core/java/com/android/server/appop/AppOpsService.java
@@ -113,7 +113,6 @@
import android.content.pm.PackageManagerInternal;
import android.content.pm.PermissionInfo;
import android.content.pm.UserInfo;
-import com.android.server.pm.pkg.component.ParsedAttribution;
import android.database.ContentObserver;
import android.hardware.camera2.CameraDevice.CAMERA_AUDIO_RESTRICTION;
import android.net.Uri;
@@ -178,6 +177,7 @@
import com.android.server.SystemServiceManager;
import com.android.server.pm.PackageList;
import com.android.server.pm.parsing.pkg.AndroidPackage;
+import com.android.server.pm.pkg.component.ParsedAttribution;
import dalvik.annotation.optimization.NeverCompile;
@@ -4551,15 +4551,16 @@
return new PackageVerificationResult(null,
/* isAttributionTagValid */ true);
}
- if (Process.isSupplemental(uid)) {
- // Supplemental processes run in their own UID range, but their associated
- // UID for checks should always be the UID of the supplemental package.
+ if (Process.isSdkSandboxUid(uid)) {
+ // SDK sandbox processes run in their own UID range, but their associated
+ // UID for checks should always be the UID of the package implementing SDK sandbox
+ // service.
// TODO: We will need to modify the callers of this function instead, so
// modifications and checks against the app ops state are done with the
// correct UID.
try {
final PackageManager pm = mContext.getPackageManager();
- final String supplementalPackageName = pm.getSupplementalProcessPackageName();
+ final String supplementalPackageName = pm.getSdkSandboxPackageName();
if (Objects.equals(packageName, supplementalPackageName)) {
int supplementalAppId = pm.getPackageUid(supplementalPackageName,
PackageManager.PackageInfoFlags.of(0));
diff --git a/services/core/java/com/android/server/audio/AudioDeviceBroker.java b/services/core/java/com/android/server/audio/AudioDeviceBroker.java
index ff7557a..270a61b 100644
--- a/services/core/java/com/android/server/audio/AudioDeviceBroker.java
+++ b/services/core/java/com/android/server/audio/AudioDeviceBroker.java
@@ -1565,6 +1565,13 @@
private AtomicBoolean mMusicMuted = new AtomicBoolean(false);
+ private static <T> boolean hasIntersection(Set<T> a, Set<T> b) {
+ for (T e : a) {
+ if (b.contains(e)) return true;
+ }
+ return false;
+ }
+
boolean messageMutesMusic(int message) {
if (message == 0) {
return false;
@@ -1574,8 +1581,8 @@
|| message == MSG_L_A2DP_DEVICE_CONNECTION_CHANGE_EXT
|| message == MSG_L_A2DP_DEVICE_CONFIG_CHANGE)
&& AudioSystem.isStreamActive(AudioSystem.STREAM_MUSIC, 0)
- && mDeviceInventory.DEVICE_OVERRIDE_A2DP_ROUTE_ON_PLUG_SET.contains(
- mAudioService.getDevicesForStream(AudioSystem.STREAM_MUSIC))) {
+ && hasIntersection(mDeviceInventory.DEVICE_OVERRIDE_A2DP_ROUTE_ON_PLUG_SET,
+ mAudioService.getDeviceSetForStream(AudioSystem.STREAM_MUSIC))) {
return false;
}
return true;
diff --git a/services/core/java/com/android/server/audio/AudioService.java b/services/core/java/com/android/server/audio/AudioService.java
index 0ff8a93..82476d8 100644
--- a/services/core/java/com/android/server/audio/AudioService.java
+++ b/services/core/java/com/android/server/audio/AudioService.java
@@ -195,6 +195,7 @@
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Set;
+import java.util.TreeSet;
import java.util.UUID;
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -1822,6 +1823,7 @@
}
// Check if device to be updated is routed for the given audio stream
+ // This may include devices such as SPEAKER_SAFE.
List<AudioDeviceAttributes> devicesForAttributes = getDevicesForAttributesInt(
new AudioAttributes.Builder().setInternalLegacyStreamType(streamType).build(),
true /* forVolume */);
@@ -3693,8 +3695,7 @@
int streamType = getBluetoothContextualVolumeStream(newMode);
- final Set<Integer> deviceTypes = AudioSystem.generateAudioDeviceTypesSet(
- mAudioSystem.getDevicesForStream(streamType));
+ final Set<Integer> deviceTypes = getDeviceSetForStreamDirect(streamType);
final Set<Integer> absVolumeMultiModeCaseDevices = AudioSystem.intersectionAudioDeviceTypes(
mAbsVolumeMultiModeCaseDevices, deviceTypes);
if (absVolumeMultiModeCaseDevices.isEmpty()) {
@@ -6258,55 +6259,107 @@
}
}
- /** only public for mocking/spying, do not call outside of AudioService */
+ /**
+ * Returns device associated with the stream volume.
+ *
+ * Only public for mocking/spying, do not call outside of AudioService.
+ * Device volume aliasing means DEVICE_OUT_SPEAKER may be returned for
+ * DEVICE_OUT_SPEAKER_SAFE.
+ */
@VisibleForTesting
public int getDeviceForStream(int stream) {
- int device = getDevicesForStreamInt(stream);
- if ((device & (device - 1)) != 0) {
+ return selectOneAudioDevice(getDeviceSetForStream(stream));
+ }
+
+ /*
+ * Must match native apm_extract_one_audio_device() used in getDeviceForVolume()
+ * or the wrong device volume may be adjusted.
+ */
+ private int selectOneAudioDevice(Set<Integer> deviceSet) {
+ if (deviceSet.isEmpty()) {
+ return AudioSystem.DEVICE_NONE;
+ } else if (deviceSet.size() == 1) {
+ return deviceSet.iterator().next();
+ } else {
// Multiple device selection is either:
// - speaker + one other device: give priority to speaker in this case.
// - one A2DP device + another device: happens with duplicated output. In this case
// retain the device on the A2DP output as the other must not correspond to an active
// selection if not the speaker.
// - HDMI-CEC system audio mode only output: give priority to available item in order.
- // FIXME: Haven't applied audio device type refactor to this API
- // as it is going to be deprecated.
- if ((device & AudioSystem.DEVICE_OUT_SPEAKER) != 0) {
- device = AudioSystem.DEVICE_OUT_SPEAKER;
- } else if ((device & AudioSystem.DEVICE_OUT_HDMI_ARC) != 0) {
- // FIXME(b/184944421): DEVICE_OUT_HDMI_EARC has two bits set,
- // so it must be handled correctly as it aliases
- // with DEVICE_OUT_HDMI_ARC | DEVICE_OUT_EARPIECE.
- device = AudioSystem.DEVICE_OUT_HDMI_ARC;
- } else if ((device & AudioSystem.DEVICE_OUT_SPDIF) != 0) {
- device = AudioSystem.DEVICE_OUT_SPDIF;
- } else if ((device & AudioSystem.DEVICE_OUT_AUX_LINE) != 0) {
- device = AudioSystem.DEVICE_OUT_AUX_LINE;
+
+ if (deviceSet.contains(AudioSystem.DEVICE_OUT_SPEAKER)) {
+ return AudioSystem.DEVICE_OUT_SPEAKER;
+ } else if (deviceSet.contains(AudioSystem.DEVICE_OUT_SPEAKER_SAFE)) {
+ // Note: DEVICE_OUT_SPEAKER_SAFE not present in getDeviceSetForStreamDirect
+ return AudioSystem.DEVICE_OUT_SPEAKER_SAFE;
+ } else if (deviceSet.contains(AudioSystem.DEVICE_OUT_HDMI_ARC)) {
+ return AudioSystem.DEVICE_OUT_HDMI_ARC;
+ } else if (deviceSet.contains(AudioSystem.DEVICE_OUT_HDMI_EARC)) {
+ return AudioSystem.DEVICE_OUT_HDMI_EARC;
+ } else if (deviceSet.contains(AudioSystem.DEVICE_OUT_AUX_LINE)) {
+ return AudioSystem.DEVICE_OUT_AUX_LINE;
+ } else if (deviceSet.contains(AudioSystem.DEVICE_OUT_SPDIF)) {
+ return AudioSystem.DEVICE_OUT_SPDIF;
} else {
- for (int deviceType : AudioSystem.DEVICE_OUT_ALL_A2DP_SET) {
- if ((deviceType & device) == deviceType) {
+ // At this point, deviceSet should contain exactly one A2DP device;
+ // regardless, return the first A2DP device in numeric order.
+ // If there is no A2DP device, this falls through to log an error.
+ for (int deviceType : deviceSet) {
+ if (AudioSystem.DEVICE_OUT_ALL_A2DP_SET.contains(deviceType)) {
return deviceType;
}
}
}
}
- return device;
+ Log.w(TAG, "selectOneAudioDevice returning DEVICE_NONE from invalid device combination "
+ + AudioSystem.deviceSetToString(deviceSet));
+ return AudioSystem.DEVICE_NONE;
}
/**
* @see AudioManager#getDevicesForStream(int)
+ * @deprecated on {@link android.os.Build.VERSION_CODES#T} as new devices
+ * will have multi-bit device types since S.
+ * Use {@link #getDevicesForAttributes()} instead.
*/
- public int getDevicesForStream(int streamType) {
+ @Override
+ @Deprecated
+ public int getDeviceMaskForStream(int streamType) {
ensureValidStreamType(streamType);
+ // no permission required
final long token = Binder.clearCallingIdentity();
try {
- return mAudioSystem.getDevicesForStream(streamType);
+ return AudioSystem.getDeviceMaskFromSet(
+ getDeviceSetForStreamDirect(streamType));
} finally {
Binder.restoreCallingIdentity(token);
}
}
- private int getDevicesForStreamInt(int stream) {
+ /**
+ * Returns the devices associated with a stream type.
+ *
+ * SPEAKER_SAFE will alias to SPEAKER.
+ */
+ @NonNull
+ private Set<Integer> getDeviceSetForStreamDirect(int stream) {
+ final AudioAttributes attr =
+ AudioProductStrategy.getAudioAttributesForStrategyWithLegacyStreamType(stream);
+ Set<Integer> deviceSet =
+ AudioSystem.generateAudioDeviceTypesSet(
+ getDevicesForAttributesInt(attr, true /* forVolume */));
+ return deviceSet;
+ }
+
+ /**
+ * Returns a reference to the list of devices for the stream, do not modify.
+ *
+ * The device returned may be aliased to the actual device whose volume curve
+ * will be used. For example DEVICE_OUT_SPEAKER_SAFE aliases to DEVICE_OUT_SPEAKER.
+ */
+ @NonNull
+ public Set<Integer> getDeviceSetForStream(int stream) {
ensureValidStreamType(stream);
synchronized (VolumeStreamState.class) {
return mStreamStates[stream].observeDevicesForStream_syncVSS(true);
@@ -6318,11 +6371,10 @@
synchronized (VolumeStreamState.class) {
for (int stream = 0; stream < mStreamStates.length; stream++) {
if (stream != skipStream) {
- int devices = mStreamStates[stream].observeDevicesForStream_syncVSS(
- false /*checkOthers*/);
-
- Set<Integer> devicesSet = AudioSystem.generateAudioDeviceTypesSet(devices);
- for (Integer device : devicesSet) {
+ Set<Integer> deviceSet =
+ mStreamStates[stream].observeDevicesForStream_syncVSS(
+ false /*checkOthers*/);
+ for (Integer device : deviceSet) {
// Update volume states for devices routed for the stream
updateVolumeStates(device, stream,
"AudioService#onObserveDevicesForAllStreams");
@@ -6643,7 +6695,7 @@
&& DEVICE_MEDIA_UNMUTED_ON_PLUG_SET.contains(newDevice)
&& mStreamStates[AudioSystem.STREAM_MUSIC].mIsMuted
&& mStreamStates[AudioSystem.STREAM_MUSIC].getIndex(newDevice) != 0
- && (newDevice & mAudioSystem.getDevicesForStream(AudioSystem.STREAM_MUSIC)) != 0) {
+ && getDeviceSetForStreamDirect(AudioSystem.STREAM_MUSIC).contains(newDevice)) {
if (DEBUG_VOL) {
Log.i(TAG, String.format("onAccessoryPlugMediaUnmute unmuting device=%d [%s]",
newDevice, AudioSystem.getOutputDeviceName(newDevice)));
@@ -7031,7 +7083,7 @@
private boolean mIsMuted;
private boolean mIsMutedInternally;
private String mVolumeIndexSettingName;
- private int mObservedDevices;
+ @NonNull private Set<Integer> mObservedDeviceSet = new TreeSet<>();
private final SparseIntArray mIndexMap = new SparseIntArray(8) {
@Override
@@ -7098,17 +7150,30 @@
}
}
+ /**
+ * Returns a list of devices associated with the stream type.
+ *
+ * This is a reference to the local list, do not modify.
+ */
@GuardedBy("VolumeStreamState.class")
- public int observeDevicesForStream_syncVSS(boolean checkOthers) {
+ @NonNull
+ public Set<Integer> observeDevicesForStream_syncVSS(
+ boolean checkOthers) {
if (!mSystemServer.isPrivileged()) {
- return AudioSystem.DEVICE_NONE;
+ return new TreeSet<Integer>();
}
- final int devices = mAudioSystem.getDevicesForStream(mStreamType);
- if (devices == mObservedDevices) {
- return devices;
+ final Set<Integer> deviceSet =
+ getDeviceSetForStreamDirect(mStreamType);
+ if (deviceSet.equals(mObservedDeviceSet)) {
+ return mObservedDeviceSet;
}
- final int prevDevices = mObservedDevices;
- mObservedDevices = devices;
+
+ // Use legacy bit masks for message signalling.
+ // TODO(b/185386781): message needs update since it uses devices bit-mask.
+ final int devices = AudioSystem.getDeviceMaskFromSet(deviceSet);
+ final int prevDevices = AudioSystem.getDeviceMaskFromSet(mObservedDeviceSet);
+
+ mObservedDeviceSet = deviceSet;
if (checkOthers) {
// one stream's devices have changed, check the others
postObserveDevicesForAllStreams(mStreamType);
@@ -7124,7 +7189,7 @@
SENDMSG_QUEUE, prevDevices /*arg1*/, devices /*arg2*/,
// ok to send reference to this object, it is final
mStreamDevicesChanged /*obj*/, 0 /*delay*/);
- return devices;
+ return mObservedDeviceSet;
}
public @Nullable String getSettingNameForDevice(int device) {
@@ -7555,19 +7620,7 @@
}
pw.println();
pw.print(" Devices: ");
- final int devices = getDevicesForStreamInt(mStreamType);
- int device, i = 0, n = 0;
- // iterate all devices from 1 to DEVICE_OUT_DEFAULT exclusive
- // (the default device is not returned by getDevicesForStreamInt)
- while ((device = 1 << i) != AudioSystem.DEVICE_OUT_DEFAULT) {
- if ((devices & device) != 0) {
- if (n++ > 0) {
- pw.print(", ");
- }
- pw.print(AudioSystem.getOutputDeviceName(device));
- }
- i++;
- }
+ pw.print(AudioSystem.deviceSetToString(getDeviceSetForStream(mStreamType)));
}
}
@@ -9324,7 +9377,9 @@
mDeviceBroker.setForceUse_Async(AudioSystem.FOR_HDMI_SYSTEM_AUDIO, config,
"setHdmiSystemAudioSupported");
}
- device = getDevicesForStreamInt(AudioSystem.STREAM_MUSIC);
+ // TODO(b/185386781): Update AudioManager API to use device list.
+ // So far, this value appears to be advisory for debug log.
+ device = getDeviceMaskForStream(AudioSystem.STREAM_MUSIC);
}
}
return device;
diff --git a/services/core/java/com/android/server/audio/AudioSystemAdapter.java b/services/core/java/com/android/server/audio/AudioSystemAdapter.java
index 6ef8e87..1429b3c 100644
--- a/services/core/java/com/android/server/audio/AudioSystemAdapter.java
+++ b/services/core/java/com/android/server/audio/AudioSystemAdapter.java
@@ -52,15 +52,13 @@
* in measured methods
*/
private static final boolean ENABLE_GETDEVICES_STATS = false;
- private static final int NB_MEASUREMENTS = 2;
- private static final int METHOD_GETDEVICESFORSTREAM = 0;
- private static final int METHOD_GETDEVICESFORATTRIBUTES = 1;
+ private static final int NB_MEASUREMENTS = 1;
+ private static final int METHOD_GETDEVICESFORATTRIBUTES = 0;
private long[] mMethodTimeNs;
private int[] mMethodCallCounter;
- private String[] mMethodNames = {"getDevicesForStream", "getDevicesForAttributes"};
+ private String[] mMethodNames = {"getDevicesForAttributes"};
private static final boolean USE_CACHE_FOR_GETDEVICES = true;
- private ConcurrentHashMap<Integer, Integer> mDevicesForStreamCache;
private ConcurrentHashMap<Pair<AudioAttributes, Boolean>, ArrayList<AudioDeviceAttributes>>
mDevicesForAttrCache;
private int[] mMethodCacheHit;
@@ -113,8 +111,6 @@
sSingletonDefaultAdapter = new AudioSystemAdapter();
AudioSystem.setRoutingCallback(sSingletonDefaultAdapter);
if (USE_CACHE_FOR_GETDEVICES) {
- sSingletonDefaultAdapter.mDevicesForStreamCache =
- new ConcurrentHashMap<>(AudioSystem.getNumStreamTypes());
sSingletonDefaultAdapter.mDevicesForAttrCache =
new ConcurrentHashMap<>(AudioSystem.getNumStreamTypes());
sSingletonDefaultAdapter.mMethodCacheHit = new int[NB_MEASUREMENTS];
@@ -131,11 +127,6 @@
if (DEBUG_CACHE) {
Log.d(TAG, "---- clearing cache ----------");
}
- if (mDevicesForStreamCache != null) {
- synchronized (mDevicesForStreamCache) {
- mDevicesForStreamCache.clear();
- }
- }
if (mDevicesForAttrCache != null) {
synchronized (mDevicesForAttrCache) {
mDevicesForAttrCache.clear();
@@ -144,60 +135,6 @@
}
/**
- * Same as {@link AudioSystem#getDevicesForStream(int)}
- * @param stream a valid stream type
- * @return a mask of device types
- */
- public int getDevicesForStream(int stream) {
- if (!ENABLE_GETDEVICES_STATS) {
- return getDevicesForStreamImpl(stream);
- }
- mMethodCallCounter[METHOD_GETDEVICESFORSTREAM]++;
- final long startTime = SystemClock.uptimeNanos();
- final int res = getDevicesForStreamImpl(stream);
- mMethodTimeNs[METHOD_GETDEVICESFORSTREAM] += SystemClock.uptimeNanos() - startTime;
- return res;
- }
-
- private int getDevicesForStreamImpl(int stream) {
- if (USE_CACHE_FOR_GETDEVICES) {
- Integer res;
- synchronized (mDevicesForStreamCache) {
- res = mDevicesForStreamCache.get(stream);
- if (res == null) {
- res = AudioSystem.getDevicesForStream(stream);
- mDevicesForStreamCache.put(stream, res);
- if (DEBUG_CACHE) {
- Log.d(TAG, mMethodNames[METHOD_GETDEVICESFORSTREAM]
- + streamDeviceToDebugString(stream, res));
- }
- return res;
- }
- // cache hit
- mMethodCacheHit[METHOD_GETDEVICESFORSTREAM]++;
- if (DEBUG_CACHE) {
- final int real = AudioSystem.getDevicesForStream(stream);
- if (res == real) {
- Log.d(TAG, mMethodNames[METHOD_GETDEVICESFORSTREAM]
- + streamDeviceToDebugString(stream, res) + " CACHE");
- } else {
- Log.e(TAG, mMethodNames[METHOD_GETDEVICESFORSTREAM]
- + streamDeviceToDebugString(stream, res)
- + " CACHE ERROR real dev=0x" + Integer.toHexString(real));
- }
- }
- }
- return res;
- }
- // not using cache
- return AudioSystem.getDevicesForStream(stream);
- }
-
- private static String streamDeviceToDebugString(int stream, int dev) {
- return " stream=" + stream + " dev=0x" + Integer.toHexString(dev);
- }
-
- /**
* Same as {@link AudioSystem#getDevicesForAttributes(AudioAttributes)}
* @param attributes the attributes for which the routing is queried
* @return the devices that the stream with the given attributes would be routed to
@@ -253,12 +190,9 @@
}
private static String attrDeviceToDebugString(@NonNull AudioAttributes attr,
- @NonNull ArrayList<AudioDeviceAttributes> devices) {
- String ds = " attrUsage=" + attr.getSystemUsage();
- for (AudioDeviceAttributes ada : devices) {
- ds = ds.concat(" dev=0x" + Integer.toHexString(ada.getInternalType()));
- }
- return ds;
+ @NonNull List<AudioDeviceAttributes> devices) {
+ return " attrUsage=" + attr.getSystemUsage() + " "
+ + AudioSystem.deviceSetToString(AudioSystem.generateAudioDeviceTypesSet(devices));
}
/**
@@ -518,20 +452,23 @@
*/
public void dump(PrintWriter pw) {
pw.println("\nAudioSystemAdapter:");
- pw.println(" mDevicesForStreamCache:");
- if (mDevicesForStreamCache != null) {
- for (Integer stream : mDevicesForStreamCache.keySet()) {
- pw.println("\t stream:" + stream + " device:"
- + AudioSystem.getOutputDeviceName(mDevicesForStreamCache.get(stream)));
- }
- }
pw.println(" mDevicesForAttrCache:");
if (mDevicesForAttrCache != null) {
for (Map.Entry<Pair<AudioAttributes, Boolean>, ArrayList<AudioDeviceAttributes>>
entry : mDevicesForAttrCache.entrySet()) {
- pw.println("\t" + entry.getKey().first + " forVolume: " + entry.getKey().second);
- for (AudioDeviceAttributes devAttr : entry.getValue()) {
- pw.println("\t\t" + devAttr);
+ final AudioAttributes attributes = entry.getKey().first;
+ try {
+ final int stream = attributes.getVolumeControlStream();
+ pw.println("\t" + attributes + " forVolume: " + entry.getKey().second
+ + " stream: "
+ + AudioSystem.STREAM_NAMES[stream] + "(" + stream + ")");
+ for (AudioDeviceAttributes devAttr : entry.getValue()) {
+ pw.println("\t\t" + devAttr);
+ }
+ } catch (IllegalArgumentException e) {
+ // dump could fail if attributes do not map to a stream.
+ pw.println("\t dump failed for attributes: " + attributes);
+ Log.e(TAG, "dump failed", e);
}
}
}
@@ -545,7 +482,8 @@
+ ": counter=" + mMethodCallCounter[i]
+ " time(ms)=" + (mMethodTimeNs[i] / 1E6)
+ (USE_CACHE_FOR_GETDEVICES
- ? (" FScacheHit=" + mMethodCacheHit[METHOD_GETDEVICESFORSTREAM]) : ""));
+ ? (" FScacheHit=" + mMethodCacheHit[METHOD_GETDEVICESFORATTRIBUTES])
+ : ""));
}
pw.println("\n");
}
diff --git a/services/core/java/com/android/server/infra/AbstractMasterSystemService.java b/services/core/java/com/android/server/infra/AbstractMasterSystemService.java
index 9e00f95..29e5f92 100644
--- a/services/core/java/com/android/server/infra/AbstractMasterSystemService.java
+++ b/services/core/java/com/android/server/infra/AbstractMasterSystemService.java
@@ -48,6 +48,7 @@
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import java.util.Objects;
@@ -168,10 +169,10 @@
private final SparseBooleanArray mDisabledByUserRestriction;
/**
- * Cache of services per user id.
+ * Cache of service list per user id.
*/
@GuardedBy("mLock")
- private final SparseArray<S> mServicesCache = new SparseArray<>();
+ private final SparseArray<List<S>> mServicesCacheList = new SparseArray<>();
/**
* Value that determines whether the per-user service should be removed from the cache when its
@@ -252,8 +253,7 @@
mServiceNameResolver = serviceNameResolver;
if (mServiceNameResolver != null) {
mServiceNameResolver.setOnTemporaryServiceNameChangedCallback(
- (u, s, t) -> onServiceNameChanged(u, s, t));
-
+ this::onServiceNameChanged);
}
if (disallowProperty == null) {
mDisabledByUserRestriction = null;
@@ -308,7 +308,7 @@
@Override // from SystemService
public void onUserStopped(@NonNull TargetUser user) {
synchronized (mLock) {
- removeCachedServiceLocked(user.getUserIdentifier());
+ removeCachedServiceListLocked(user.getUserIdentifier());
}
}
@@ -386,21 +386,58 @@
synchronized (mLock) {
final S oldService = peekServiceForUserLocked(userId);
if (oldService != null) {
- oldService.removeSelfFromCacheLocked();
+ oldService.removeSelfFromCache();
}
mServiceNameResolver.setTemporaryService(userId, componentName, durationMs);
}
}
/**
+ * Temporarily sets the service implementation.
+ *
+ * <p>Typically used by Shell command and/or CTS tests.
+ *
+ * @param componentNames list of the names of the new component
+ * @param durationMs how long the change will be valid (the service will be automatically
+ * reset
+ * to the default component after this timeout expires).
+ * @throws SecurityException if caller is not allowed to manage this service's settings.
+ * @throws IllegalArgumentException if value of {@code durationMs} is higher than
+ * {@link #getMaximumTemporaryServiceDurationMs()}.
+ */
+ public final void setTemporaryServices(@UserIdInt int userId, @NonNull String[] componentNames,
+ int durationMs) {
+ Slog.i(mTag, "setTemporaryService(" + userId + ") to " + Arrays.toString(componentNames)
+ + " for " + durationMs + "ms");
+ if (mServiceNameResolver == null) {
+ return;
+ }
+ enforceCallingPermissionForManagement();
+
+ Objects.requireNonNull(componentNames);
+ final int maxDurationMs = getMaximumTemporaryServiceDurationMs();
+ if (durationMs > maxDurationMs) {
+ throw new IllegalArgumentException(
+ "Max duration is " + maxDurationMs + " (called with " + durationMs + ")");
+ }
+
+ synchronized (mLock) {
+ final S oldService = peekServiceForUserLocked(userId);
+ if (oldService != null) {
+ oldService.removeSelfFromCache();
+ }
+ mServiceNameResolver.setTemporaryServices(userId, componentNames, durationMs);
+ }
+ }
+
+ /**
* Sets whether the default service should be used.
*
* <p>Typically used during CTS tests to make sure only the default service doesn't interfere
* with the test results.
*
- * @throws SecurityException if caller is not allowed to manage this service's settings.
- *
* @return whether the enabled state changed.
+ * @throws SecurityException if caller is not allowed to manage this service's settings.
*/
public final boolean setDefaultServiceEnabled(@UserIdInt int userId, boolean enabled) {
Slog.i(mTag, "setDefaultServiceEnabled() for userId " + userId + ": " + enabled);
@@ -420,7 +457,7 @@
final S oldService = peekServiceForUserLocked(userId);
if (oldService != null) {
- oldService.removeSelfFromCacheLocked();
+ oldService.removeSelfFromCache();
}
// Must update the service on cache so its initialization code is triggered
@@ -501,6 +538,21 @@
protected abstract S newServiceLocked(@UserIdInt int resolvedUserId, boolean disabled);
/**
+ * Creates a new service list that will be added to the cache.
+ *
+ * @param resolvedUserId the resolved user id for the service.
+ * @param disabled whether the service is currently disabled (due to {@link UserManager}
+ * restrictions).
+ * @return a new instance.
+ */
+ @Nullable
+ @GuardedBy("mLock")
+ protected List<S> newServiceListLocked(@UserIdInt int resolvedUserId, boolean disabled,
+ String[] serviceNames) {
+ throw new UnsupportedOperationException("newServiceListLocked not implemented. ");
+ }
+
+ /**
* Register the service for extra Settings changes (i.e., other than
* {@link android.provider.Settings.Secure#USER_SETUP_COMPLETE} or
* {@link #getServiceSettingsProperty()}, which are automatically handled).
@@ -516,7 +568,6 @@
* <p><b>NOTE: </p>it doesn't need to register for
* {@link android.provider.Settings.Secure#USER_SETUP_COMPLETE} or
* {@link #getServiceSettingsProperty()}.
- *
*/
@SuppressWarnings("unused")
protected void registerForExtraSettingsChanges(@NonNull ContentResolver resolver,
@@ -527,7 +578,7 @@
* Callback for Settings changes that were registered though
* {@link #registerForExtraSettingsChanges(ContentResolver, ContentObserver)}.
*
- * @param userId user associated with the change
+ * @param userId user associated with the change
* @param property Settings property changed.
*/
protected void onSettingsChanged(@UserIdInt int userId, @NonNull String property) {
@@ -539,18 +590,38 @@
@GuardedBy("mLock")
@NonNull
protected S getServiceForUserLocked(@UserIdInt int userId) {
+ List<S> services = getServiceListForUserLocked(userId);
+ return services == null || services.size() == 0 ? null : services.get(0);
+ }
+
+ /**
+ * Gets the service instance list for a user, creating instances if not present in the cache.
+ */
+ @GuardedBy("mLock")
+ protected List<S> getServiceListForUserLocked(@UserIdInt int userId) {
final int resolvedUserId = ActivityManager.handleIncomingUser(Binder.getCallingPid(),
Binder.getCallingUid(), userId, false, false, null, null);
- S service = mServicesCache.get(resolvedUserId);
- if (service == null) {
+ List<S> services = mServicesCacheList.get(resolvedUserId);
+ if (services == null || services.size() == 0) {
final boolean disabled = isDisabledLocked(userId);
- service = newServiceLocked(resolvedUserId, disabled);
- if (!disabled) {
- onServiceEnabledLocked(service, resolvedUserId);
+ if (mServiceNameResolver == null) {
+ return null;
}
- mServicesCache.put(userId, service);
+ if (mServiceNameResolver.isConfiguredInMultipleMode()) {
+ services = newServiceListLocked(resolvedUserId, disabled,
+ mServiceNameResolver.getServiceNameList(userId));
+ } else {
+ services = new ArrayList<>();
+ services.add(newServiceLocked(resolvedUserId, disabled));
+ }
+ if (!disabled) {
+ for (int i = 0; i < services.size(); i++) {
+ onServiceEnabledLocked(services.get(i), resolvedUserId);
+ }
+ }
+ mServicesCacheList.put(userId, services);
}
- return service;
+ return services;
}
/**
@@ -560,9 +631,20 @@
@GuardedBy("mLock")
@Nullable
protected S peekServiceForUserLocked(@UserIdInt int userId) {
+ List<S> serviceList = peekServiceListForUserLocked(userId);
+ return serviceList == null || serviceList.size() == 0 ? null : serviceList.get(0);
+ }
+
+ /**
+ * Gets the <b>existing</b> service instance for a user, returning {@code null} if not already
+ * present in the cache.
+ */
+ @GuardedBy("mLock")
+ @Nullable
+ protected List<S> peekServiceListForUserLocked(@UserIdInt int userId) {
final int resolvedUserId = ActivityManager.handleIncomingUser(Binder.getCallingPid(),
Binder.getCallingUid(), userId, false, false, null, null);
- return mServicesCache.get(resolvedUserId);
+ return mServicesCacheList.get(resolvedUserId);
}
/**
@@ -570,36 +652,59 @@
*/
@GuardedBy("mLock")
protected void updateCachedServiceLocked(@UserIdInt int userId) {
- updateCachedServiceLocked(userId, isDisabledLocked(userId));
+ updateCachedServiceListLocked(userId, isDisabledLocked(userId));
}
/**
* Checks whether the service is disabled (through {@link UserManager} restrictions) for the
* given user.
*/
+ @GuardedBy("mLock")
protected boolean isDisabledLocked(@UserIdInt int userId) {
- return mDisabledByUserRestriction == null ? false : mDisabledByUserRestriction.get(userId);
+ return mDisabledByUserRestriction != null && mDisabledByUserRestriction.get(userId);
}
/**
* Updates a cached service for a given user.
*
- * @param userId user handle.
+ * @param userId user handle.
* @param disabled whether the user is disabled.
* @return service for the user.
*/
@GuardedBy("mLock")
protected S updateCachedServiceLocked(@UserIdInt int userId, boolean disabled) {
final S service = getServiceForUserLocked(userId);
- if (service != null) {
- service.updateLocked(disabled);
- if (!service.isEnabledLocked()) {
- removeCachedServiceLocked(userId);
- } else {
- onServiceEnabledLocked(service, userId);
+ updateCachedServiceListLocked(userId, disabled);
+ return service;
+ }
+
+ /**
+ * Updates a cached service for a given user.
+ *
+ * @param userId user handle.
+ * @param disabled whether the user is disabled.
+ * @return service for the user.
+ */
+ @GuardedBy("mLock")
+ protected List<S> updateCachedServiceListLocked(@UserIdInt int userId, boolean disabled) {
+ final List<S> services = getServiceListForUserLocked(userId);
+ if (services == null) {
+ return null;
+ }
+ for (int i = 0; i < services.size(); i++) {
+ S service = services.get(i);
+ if (service != null) {
+ synchronized (service.mLock) {
+ service.updateLocked(disabled);
+ if (!service.isEnabledLocked()) {
+ removeCachedServiceListLocked(userId);
+ } else {
+ onServiceEnabledLocked(services.get(i), userId);
+ }
+ }
}
}
- return service;
+ return services;
}
/**
@@ -619,28 +724,32 @@
* <p>By default doesn't do anything, but can be overridden by subclasses.
*/
@SuppressWarnings("unused")
+ @GuardedBy("mLock")
protected void onServiceEnabledLocked(@NonNull S service, @UserIdInt int userId) {
}
/**
- * Removes a cached service for a given user.
+ * Removes a cached service list for a given user.
*
* @return the removed service.
*/
@GuardedBy("mLock")
@NonNull
- protected final S removeCachedServiceLocked(@UserIdInt int userId) {
- final S service = peekServiceForUserLocked(userId);
- if (service != null) {
- mServicesCache.delete(userId);
- onServiceRemoved(service, userId);
+ protected final List<S> removeCachedServiceListLocked(@UserIdInt int userId) {
+ final List<S> services = peekServiceListForUserLocked(userId);
+ if (services != null) {
+ mServicesCacheList.delete(userId);
+ for (int i = 0; i < services.size(); i++) {
+ onServiceRemoved(services.get(i), userId);
+ }
}
- return service;
+ return services;
}
/**
* Called before the package that provides the service for the given user is being updated.
*/
+ @GuardedBy("mLock")
protected void onServicePackageUpdatingLocked(@UserIdInt int userId) {
if (verbose) Slog.v(mTag, "onServicePackageUpdatingLocked(" + userId + ")");
}
@@ -648,6 +757,7 @@
/**
* Called after the package that provides the service for the given user is being updated.
*/
+ @GuardedBy("mLock")
protected void onServicePackageUpdatedLocked(@UserIdInt int userId) {
if (verbose) Slog.v(mTag, "onServicePackageUpdated(" + userId + ")");
}
@@ -655,6 +765,7 @@
/**
* Called after the package data that provides the service for the given user is cleared.
*/
+ @GuardedBy("mLock")
protected void onServicePackageDataClearedLocked(@UserIdInt int userId) {
if (verbose) Slog.v(mTag, "onServicePackageDataCleared(" + userId + ")");
}
@@ -662,6 +773,7 @@
/**
* Called after the package that provides the service for the given user is restarted.
*/
+ @GuardedBy("mLock")
protected void onServicePackageRestartedLocked(@UserIdInt int userId) {
if (verbose) Slog.v(mTag, "onServicePackageRestarted(" + userId + ")");
}
@@ -679,14 +791,31 @@
* <p>By default, it calls {@link #updateCachedServiceLocked(int)}; subclasses must either call
* that same method, or {@code super.onServiceNameChanged()}.
*
- * @param userId user handle.
+ * @param userId user handle.
* @param serviceName the new service name.
* @param isTemporary whether the new service is temporary.
*/
protected void onServiceNameChanged(@UserIdInt int userId, @Nullable String serviceName,
boolean isTemporary) {
synchronized (mLock) {
- updateCachedServiceLocked(userId);
+ updateCachedServiceListLocked(userId, isDisabledLocked(userId));
+ }
+ }
+
+ /**
+ * Called when the service name list has changed (typically when using temporary services).
+ *
+ * <p>By default, it calls {@link #updateCachedServiceLocked(int)}; subclasses must either call
+ * that same method, or {@code super.onServiceNameChanged()}.
+ *
+ * @param userId user handle.
+ * @param serviceNames the new service name list.
+ * @param isTemporary whether the new service is temporary.
+ */
+ protected void onServiceNameListChanged(@UserIdInt int userId, @Nullable String[] serviceNames,
+ boolean isTemporary) {
+ synchronized (mLock) {
+ updateCachedServiceListLocked(userId, isDisabledLocked(userId));
}
}
@@ -695,9 +824,12 @@
*/
@GuardedBy("mLock")
protected void visitServicesLocked(@NonNull Visitor<S> visitor) {
- final int size = mServicesCache.size();
+ final int size = mServicesCacheList.size();
for (int i = 0; i < size; i++) {
- visitor.visit(mServicesCache.valueAt(i));
+ List<S> services = mServicesCacheList.valueAt(i);
+ for (int j = 0; j < services.size(); j++) {
+ visitor.visit(services.get(j));
+ }
}
}
@@ -706,7 +838,7 @@
*/
@GuardedBy("mLock")
protected void clearCacheLocked() {
- mServicesCache.clear();
+ mServicesCacheList.clear();
}
/**
@@ -757,6 +889,7 @@
}
// TODO(b/117779333): support proto
+ @GuardedBy("mLock")
protected void dumpLocked(@NonNull String prefix, @NonNull PrintWriter pw) {
boolean realDebug = debug;
boolean realVerbose = verbose;
@@ -765,40 +898,64 @@
try {
// Temporarily turn on full logging;
debug = verbose = true;
- final int size = mServicesCache.size();
- pw.print(prefix); pw.print("Debug: "); pw.print(realDebug);
- pw.print(" Verbose: "); pw.println(realVerbose);
- pw.print("Package policy flags: "); pw.println(mServicePackagePolicyFlags);
+ final int size = mServicesCacheList.size();
+ pw.print(prefix);
+ pw.print("Debug: ");
+ pw.print(realDebug);
+ pw.print(" Verbose: ");
+ pw.println(realVerbose);
+ pw.print("Package policy flags: ");
+ pw.println(mServicePackagePolicyFlags);
if (mUpdatingPackageNames != null) {
- pw.print("Packages being updated: "); pw.println(mUpdatingPackageNames);
+ pw.print("Packages being updated: ");
+ pw.println(mUpdatingPackageNames);
}
dumpSupportedUsers(pw, prefix);
if (mServiceNameResolver != null) {
- pw.print(prefix); pw.print("Name resolver: ");
- mServiceNameResolver.dumpShort(pw); pw.println();
+ pw.print(prefix);
+ pw.print("Name resolver: ");
+ mServiceNameResolver.dumpShort(pw);
+ pw.println();
final List<UserInfo> users = getSupportedUsers();
for (int i = 0; i < users.size(); i++) {
final int userId = users.get(i).id;
- pw.print(prefix2); pw.print(userId); pw.print(": ");
- mServiceNameResolver.dumpShort(pw, userId); pw.println();
+ pw.print(prefix2);
+ pw.print(userId);
+ pw.print(": ");
+ mServiceNameResolver.dumpShort(pw, userId);
+ pw.println();
}
}
- pw.print(prefix); pw.print("Users disabled by restriction: ");
+ pw.print(prefix);
+ pw.print("Users disabled by restriction: ");
pw.println(mDisabledByUserRestriction);
- pw.print(prefix); pw.print("Allow instant service: "); pw.println(mAllowInstantService);
+ pw.print(prefix);
+ pw.print("Allow instant service: ");
+ pw.println(mAllowInstantService);
final String settingsProperty = getServiceSettingsProperty();
if (settingsProperty != null) {
- pw.print(prefix); pw.print("Settings property: "); pw.println(settingsProperty);
+ pw.print(prefix);
+ pw.print("Settings property: ");
+ pw.println(settingsProperty);
}
- pw.print(prefix); pw.print("Cached services: ");
+ pw.print(prefix);
+ pw.print("Cached services: ");
if (size == 0) {
pw.println("none");
} else {
pw.println(size);
for (int i = 0; i < size; i++) {
- pw.print(prefix); pw.print("Service at "); pw.print(i); pw.println(": ");
- final S service = mServicesCache.valueAt(i);
- service.dumpLocked(prefix2, pw);
+ pw.print(prefix);
+ pw.print("Service at ");
+ pw.print(i);
+ pw.println(": ");
+ final List<S> services = mServicesCacheList.valueAt(i);
+ for (int j = 0; j < services.size(); j++) {
+ S service = services.get(i);
+ synchronized (service.mLock) {
+ service.dumpLocked(prefix2, pw);
+ }
+ }
pw.println();
}
}
@@ -820,7 +977,7 @@
final int userId = getChangingUserId();
synchronized (mLock) {
if (mUpdatingPackageNames == null) {
- mUpdatingPackageNames = new SparseArray<String>(mServicesCache.size());
+ mUpdatingPackageNames = new SparseArray<String>(mServicesCacheList.size());
}
mUpdatingPackageNames.put(userId, packageName);
onServicePackageUpdatingLocked(userId);
@@ -835,7 +992,7 @@
+ " because package " + activePackageName
+ " is being updated");
}
- removeCachedServiceLocked(userId);
+ removeCachedServiceListLocked(userId);
if ((mServicePackagePolicyFlags & PACKAGE_UPDATE_POLICY_REFRESH_EAGER)
!= 0) {
@@ -901,7 +1058,7 @@
if (Intent.ACTION_PACKAGE_RESTARTED.equals(action)) {
handleActiveServiceRestartedLocked(activePackageName, userId);
} else {
- removeCachedServiceLocked(userId);
+ removeCachedServiceListLocked(userId);
}
} else {
handlePackageUpdateLocked(pkg);
@@ -930,7 +1087,7 @@
private void handleActiveServiceRemoved(@UserIdInt int userId) {
synchronized (mLock) {
- removeCachedServiceLocked(userId);
+ removeCachedServiceListLocked(userId);
}
final String serviceSettingsProperty = getServiceSettingsProperty();
if (serviceSettingsProperty != null) {
@@ -939,6 +1096,7 @@
}
}
+ @GuardedBy("mLock")
private void handleActiveServiceRestartedLocked(String activePackageName,
@UserIdInt int userId) {
if ((mServicePackagePolicyFlags & PACKAGE_RESTART_POLICY_NO_REFRESH) != 0) {
@@ -952,7 +1110,7 @@
+ " because package " + activePackageName
+ " is being restarted");
}
- removeCachedServiceLocked(userId);
+ removeCachedServiceListLocked(userId);
if ((mServicePackagePolicyFlags & PACKAGE_RESTART_POLICY_REFRESH_EAGER) != 0) {
if (debug) {
@@ -966,14 +1124,27 @@
@Override
public void onPackageModified(String packageName) {
- if (verbose) Slog.v(mTag, "onPackageModified(): " + packageName);
+ synchronized (mLock) {
+ if (verbose) Slog.v(mTag, "onPackageModified(): " + packageName);
- if (mServiceNameResolver == null) {
- return;
+ if (mServiceNameResolver == null) {
+ return;
+ }
+
+ final int userId = getChangingUserId();
+ final String[] serviceNames = mServiceNameResolver.getDefaultServiceNameList(
+ userId);
+ if (serviceNames != null) {
+ for (int i = 0; i < serviceNames.length; i++) {
+ peekAndUpdateCachedServiceLocked(packageName, userId, serviceNames[i]);
+ }
+ }
}
+ }
- final int userId = getChangingUserId();
- final String serviceName = mServiceNameResolver.getDefaultServiceName(userId);
+ @GuardedBy("mLock")
+ private void peekAndUpdateCachedServiceLocked(String packageName, int userId,
+ String serviceName) {
if (serviceName == null) {
return;
}
@@ -997,6 +1168,7 @@
}
}
+ @GuardedBy("mLock")
private String getActiveServicePackageNameLocked() {
final int userId = getChangingUserId();
final S service = peekServiceForUserLocked(userId);
@@ -1017,7 +1189,7 @@
};
// package changes
- monitor.register(getContext(), null, UserHandle.ALL, true);
+ monitor.register(getContext(), null, UserHandle.ALL, true);
}
/**
diff --git a/services/core/java/com/android/server/infra/AbstractPerUserSystemService.java b/services/core/java/com/android/server/infra/AbstractPerUserSystemService.java
index 757a5cc..58413c9 100644
--- a/services/core/java/com/android/server/infra/AbstractPerUserSystemService.java
+++ b/services/core/java/com/android/server/infra/AbstractPerUserSystemService.java
@@ -43,14 +43,13 @@
*
* @param <M> "main" service class.
* @param <S> "real" service class.
- *
* @hide
*/
public abstract class AbstractPerUserSystemService<S extends AbstractPerUserSystemService<S, M>,
M extends AbstractMasterSystemService<M, S>> {
- protected final @UserIdInt int mUserId;
- protected final Object mLock;
+ @UserIdInt protected final int mUserId;
+ public final Object mLock;
protected final String mTag = getClass().getSimpleName();
protected final M mMaster;
@@ -91,14 +90,14 @@
* <p><b>MUST</b> be overridden by subclasses that bind to an
* {@link com.android.internal.infra.AbstractRemoteService}.
*
- * @throws NameNotFoundException if the service does not exist.
- * @throws SecurityException if the service does not have the proper permissions to be bound to.
- * @throws UnsupportedOperationException if subclass binds to a remote service but does not
- * overrides it.
- *
* @return new {@link ServiceInfo},
+ * @throws NameNotFoundException if the service does not exist.
+ * @throws SecurityException if the service does not have the proper permissions to
+ * be bound to.
+ * @throws UnsupportedOperationException if subclass binds to a remote service but does not
+ * overrides it.
*/
- protected @NonNull ServiceInfo newServiceInfoLocked(
+ @NonNull protected ServiceInfo newServiceInfoLocked(
@SuppressWarnings("unused") @NonNull ComponentName serviceComponent)
throws NameNotFoundException {
throw new UnsupportedOperationException("not overridden");
@@ -137,7 +136,6 @@
* previous state.
*
* @param disabled whether the service is disabled (due to {@link UserManager} restrictions).
- *
* @return whether the disabled state changed.
*/
@GuardedBy("mLock")
@@ -154,18 +152,48 @@
updateIsSetupComplete(mUserId);
mDisabled = disabled;
- updateServiceInfoLocked();
+ if (mMaster.mServiceNameResolver.isConfiguredInMultipleMode()) {
+ updateServiceInfoListLocked();
+ } else {
+ updateServiceInfoLocked();
+ }
return wasEnabled != isEnabledLocked();
}
/**
* Updates the internal reference to the service info, and returns the service's component.
*/
+ @GuardedBy("mLock")
protected final ComponentName updateServiceInfoLocked() {
- ComponentName serviceComponent = null;
- if (mMaster.mServiceNameResolver != null) {
- ServiceInfo serviceInfo = null;
+ ComponentName[] componentNames = updateServiceInfoListLocked();
+ return componentNames == null || componentNames.length == 0 ? null : componentNames[0];
+ }
+
+ /**
+ * Updates the internal reference to the service info, and returns the service's component.
+ */
+ @GuardedBy("mLock")
+ protected final ComponentName[] updateServiceInfoListLocked() {
+ if (mMaster.mServiceNameResolver == null) {
+ return null;
+ }
+ if (!mMaster.mServiceNameResolver.isConfiguredInMultipleMode()) {
final String componentName = getComponentNameLocked();
+ return new ComponentName[] { getServiceComponent(componentName) };
+ }
+ final String[] componentNames = mMaster.mServiceNameResolver.getServiceNameList(
+ mUserId);
+ ComponentName[] serviceComponents = new ComponentName[componentNames.length];
+ for (int i = 0; i < componentNames.length; i++) {
+ serviceComponents[i] = getServiceComponent(componentNames[i]);
+ }
+ return serviceComponents;
+ }
+
+ private ComponentName getServiceComponent(String componentName) {
+ synchronized (mLock) {
+ ServiceInfo serviceInfo = null;
+ ComponentName serviceComponent = null;
if (!TextUtils.isEmpty(componentName)) {
try {
serviceComponent = ComponentName.unflattenFromString(componentName);
@@ -196,14 +224,14 @@
Slog.e(mTag, "Bad ServiceInfo for '" + componentName + "': " + e);
mServiceInfo = null;
}
+ return serviceComponent;
}
- return serviceComponent;
}
/**
* Gets the user associated with this service.
*/
- public final @UserIdInt int getUserId() {
+ @UserIdInt public final int getUserId() {
return mUserId;
}
@@ -229,15 +257,34 @@
/**
* Gets the current name of the service, which is either the default service or the
- * {@link AbstractMasterSystemService#setTemporaryService(int, String, int) temporary one}.
+ * {@link AbstractMasterSystemService#setTemporaryService(int, String, int) temporary one}.
*/
- protected final @Nullable String getComponentNameLocked() {
+ @Nullable
+ @GuardedBy("mLock")
+ protected final String getComponentNameLocked() {
return mMaster.mServiceNameResolver.getServiceName(mUserId);
}
/**
+ * Gets the current name of the service, which is either the default service or the
+ * {@link AbstractMasterSystemService#setTemporaryService(int, String, int) temporary one}.
+ */
+ @Nullable
+ @GuardedBy("mLock")
+ protected final String getComponentNameForMultipleLocked(String serviceName) {
+ String[] services = mMaster.mServiceNameResolver.getServiceNameList(mUserId);
+ for (int i = 0; i < services.length; i++) {
+ if (serviceName.equals(services[i])) {
+ return services[i];
+ }
+ }
+ return null;
+ }
+
+ /**
* Checks whether the current service for the user was temporarily set.
*/
+ @GuardedBy("mLock")
public final boolean isTemporaryServiceSetLocked() {
return mMaster.mServiceNameResolver.isTemporary(mUserId);
}
@@ -245,6 +292,7 @@
/**
* Resets the temporary service implementation to the default component.
*/
+ @GuardedBy("mLock")
protected final void resetTemporaryServiceLocked() {
mMaster.mServiceNameResolver.resetTemporaryService(mUserId);
}
@@ -268,6 +316,7 @@
return mServiceInfo == null ? null : mServiceInfo.getComponentName();
}
}
+
/**
* Gets the name of the of the app this service binds to, or {@code null} if the service is
* disabled.
@@ -303,8 +352,10 @@
/**
* Removes the service from the main service's cache.
*/
- protected final void removeSelfFromCacheLocked() {
- mMaster.removeCachedServiceLocked(mUserId);
+ protected final void removeSelfFromCache() {
+ synchronized (mMaster.mLock) {
+ mMaster.removeCachedServiceListLocked(mUserId);
+ }
}
/**
@@ -327,6 +378,7 @@
* Gets the target SDK level of the service this service binds to,
* or {@code 0} if the service is disabled.
*/
+ @GuardedBy("mLock")
public final int getTargedSdkLocked() {
return mServiceInfo == null ? 0 : mServiceInfo.applicationInfo.targetSdkVersion;
}
@@ -334,6 +386,7 @@
/**
* Gets whether the device already finished setup.
*/
+ @GuardedBy("mLock")
protected final boolean isSetupCompletedLocked() {
return mSetupComplete;
}
@@ -348,19 +401,32 @@
// TODO(b/117779333): support proto
@GuardedBy("mLock")
protected void dumpLocked(@NonNull String prefix, @NonNull PrintWriter pw) {
- pw.print(prefix); pw.print("User: "); pw.println(mUserId);
+ pw.print(prefix);
+ pw.print("User: ");
+ pw.println(mUserId);
if (mServiceInfo != null) {
- pw.print(prefix); pw.print("Service Label: "); pw.println(getServiceLabelLocked());
- pw.print(prefix); pw.print("Target SDK: "); pw.println(getTargedSdkLocked());
+ pw.print(prefix);
+ pw.print("Service Label: ");
+ pw.println(getServiceLabelLocked());
+ pw.print(prefix);
+ pw.print("Target SDK: ");
+ pw.println(getTargedSdkLocked());
}
if (mMaster.mServiceNameResolver != null) {
- pw.print(prefix); pw.print("Name resolver: ");
- mMaster.mServiceNameResolver.dumpShort(pw, mUserId); pw.println();
+ pw.print(prefix);
+ pw.print("Name resolver: ");
+ mMaster.mServiceNameResolver.dumpShort(pw, mUserId);
+ pw.println();
}
- pw.print(prefix); pw.print("Disabled by UserManager: "); pw.println(mDisabled);
- pw.print(prefix); pw.print("Setup complete: "); pw.println(mSetupComplete);
+ pw.print(prefix);
+ pw.print("Disabled by UserManager: ");
+ pw.println(mDisabled);
+ pw.print(prefix);
+ pw.print("Setup complete: ");
+ pw.println(mSetupComplete);
if (mServiceInfo != null) {
- pw.print(prefix); pw.print("Service UID: ");
+ pw.print(prefix);
+ pw.print("Service UID: ");
pw.println(mServiceInfo.applicationInfo.uid);
}
pw.println();
diff --git a/services/core/java/com/android/server/infra/FrameworkResourcesServiceNameResolver.java b/services/core/java/com/android/server/infra/FrameworkResourcesServiceNameResolver.java
index 35d5956..db2cb52 100644
--- a/services/core/java/com/android/server/infra/FrameworkResourcesServiceNameResolver.java
+++ b/services/core/java/com/android/server/infra/FrameworkResourcesServiceNameResolver.java
@@ -15,6 +15,7 @@
*/
package com.android.server.infra;
+import android.annotation.ArrayRes;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.StringRes;
@@ -33,6 +34,7 @@
import com.android.internal.annotations.GuardedBy;
import java.io.PrintWriter;
+import java.util.Arrays;
/**
* Gets the service name using a framework resources, temporarily changing the service if necessary
@@ -47,20 +49,20 @@
/** Handler message to {@link #resetTemporaryService(int)} */
private static final int MSG_RESET_TEMPORARY_SERVICE = 0;
- private final @NonNull Context mContext;
- private final @NonNull Object mLock = new Object();
- private final @StringRes int mResourceId;
- private @Nullable NameResolverListener mOnSetCallback;
-
+ @NonNull private final Context mContext;
+ @NonNull private final Object mLock = new Object();
+ @StringRes private final int mStringResourceId;
+ @ArrayRes private final int mArrayResourceId;
+ private final boolean mIsMultiple;
/**
- * Map of temporary service name set by {@link #setTemporaryService(int, String, int)},
+ * Map of temporary service name list set by {@link #setTemporaryServices(int, String[], int)},
* keyed by {@code userId}.
*
- * <p>Typically used by Shell command and/or CTS tests.
+ * <p>Typically used by Shell command and/or CTS tests to configure temporary services if
+ * mIsMultiple is true.
*/
@GuardedBy("mLock")
- private final SparseArray<String> mTemporaryServiceNames = new SparseArray<>();
-
+ private final SparseArray<String[]> mTemporaryServiceNamesList = new SparseArray<>();
/**
* Map of default services that have been disabled by
* {@link #setDefaultServiceEnabled(int, boolean)},keyed by {@code userId}.
@@ -69,7 +71,7 @@
*/
@GuardedBy("mLock")
private final SparseBooleanArray mDefaultServicesDisabled = new SparseBooleanArray();
-
+ @Nullable private NameResolverListener mOnSetCallback;
/**
* When the temporary service will expire (and reset back to the default).
*/
@@ -85,7 +87,22 @@
public FrameworkResourcesServiceNameResolver(@NonNull Context context,
@StringRes int resourceId) {
mContext = context;
- mResourceId = resourceId;
+ mStringResourceId = resourceId;
+ mArrayResourceId = -1;
+ mIsMultiple = false;
+ }
+
+ public FrameworkResourcesServiceNameResolver(@NonNull Context context,
+ @ArrayRes int resourceId, boolean isMultiple) {
+ if (!isMultiple) {
+ throw new UnsupportedOperationException("Please use "
+ + "FrameworkResourcesServiceNameResolver(context, @StringRes int) constructor "
+ + "if single service mode is requested.");
+ }
+ mContext = context;
+ mStringResourceId = -1;
+ mArrayResourceId = resourceId;
+ mIsMultiple = true;
}
@Override
@@ -96,22 +113,31 @@
}
@Override
- public String getDefaultServiceName(@UserIdInt int userId) {
- synchronized (mLock) {
- final String name = mContext.getString(mResourceId);
- return TextUtils.isEmpty(name) ? null : name;
- }
+ public String getServiceName(@UserIdInt int userId) {
+ String[] serviceNames = getServiceNameList(userId);
+ return (serviceNames == null || serviceNames.length == 0) ? null : serviceNames[0];
}
@Override
- public String getServiceName(@UserIdInt int userId) {
+ public String getDefaultServiceName(@UserIdInt int userId) {
+ String[] serviceNames = getDefaultServiceNameList(userId);
+ return (serviceNames == null || serviceNames.length == 0) ? null : serviceNames[0];
+ }
+
+ /**
+ * Gets the default list of the service names for the given user.
+ *
+ * <p>Typically implemented by services which want to provide multiple backends.
+ */
+ @Override
+ public String[] getServiceNameList(int userId) {
synchronized (mLock) {
- final String temporaryName = mTemporaryServiceNames.get(userId);
- if (temporaryName != null) {
+ String[] temporaryNames = mTemporaryServiceNamesList.get(userId);
+ if (temporaryNames != null) {
// Always log it, as it should only be used on CTS or during development
- Slog.w(TAG, "getServiceName(): using temporary name " + temporaryName
- + " for user " + userId);
- return temporaryName;
+ Slog.w(TAG, "getServiceName(): using temporary name "
+ + Arrays.toString(temporaryNames) + " for user " + userId);
+ return temporaryNames;
}
final boolean disabled = mDefaultServicesDisabled.get(userId);
if (disabled) {
@@ -120,22 +146,50 @@
+ "user " + userId);
return null;
}
- return getDefaultServiceName(userId);
+ return getDefaultServiceNameList(userId);
+
}
}
+ /**
+ * Gets the default list of the service names for the given user.
+ *
+ * <p>Typically implemented by services which want to provide multiple backends.
+ */
+ @Override
+ public String[] getDefaultServiceNameList(int userId) {
+ synchronized (mLock) {
+ if (mIsMultiple) {
+ return mContext.getResources().getStringArray(mArrayResourceId);
+ } else {
+ final String name = mContext.getString(mStringResourceId);
+ return TextUtils.isEmpty(name) ? new String[0] : new String[] { name };
+ }
+ }
+ }
+
+ @Override
+ public boolean isConfiguredInMultipleMode() {
+ return mIsMultiple;
+ }
+
@Override
public boolean isTemporary(@UserIdInt int userId) {
synchronized (mLock) {
- return mTemporaryServiceNames.get(userId) != null;
+ return mTemporaryServiceNamesList.get(userId) != null;
}
}
@Override
public void setTemporaryService(@UserIdInt int userId, @NonNull String componentName,
int durationMs) {
+ setTemporaryServices(userId, new String[]{componentName}, durationMs);
+ }
+
+ @Override
+ public void setTemporaryServices(int userId, @NonNull String[] componentNames, int durationMs) {
synchronized (mLock) {
- mTemporaryServiceNames.put(userId, componentName);
+ mTemporaryServiceNamesList.put(userId, componentNames);
if (mTemporaryHandler == null) {
mTemporaryHandler = new Handler(Looper.getMainLooper(), null, true) {
@@ -155,8 +209,10 @@
}
mTemporaryServiceExpiration = SystemClock.elapsedRealtime() + durationMs;
mTemporaryHandler.sendEmptyMessageDelayed(MSG_RESET_TEMPORARY_SERVICE, durationMs);
- notifyTemporaryServiceNameChangedLocked(userId, componentName,
- /* isTemporary= */ true);
+ for (int i = 0; i < componentNames.length; i++) {
+ notifyTemporaryServiceNameChangedLocked(userId, componentNames[i],
+ /* isTemporary= */ true);
+ }
}
}
@@ -164,8 +220,8 @@
public void resetTemporaryService(@UserIdInt int userId) {
synchronized (mLock) {
Slog.i(TAG, "resetting temporary service for user " + userId + " from "
- + mTemporaryServiceNames.get(userId));
- mTemporaryServiceNames.remove(userId);
+ + Arrays.toString(mTemporaryServiceNamesList.get(userId)));
+ mTemporaryServiceNamesList.remove(userId);
if (mTemporaryHandler != null) {
mTemporaryHandler.removeMessages(MSG_RESET_TEMPORARY_SERVICE);
mTemporaryHandler = null;
@@ -207,16 +263,21 @@
@Override
public String toString() {
- return "FrameworkResourcesServiceNamer[temps=" + mTemporaryServiceNames + "]";
+ synchronized (mLock) {
+ return "FrameworkResourcesServiceNamer[temps=" + mTemporaryServiceNamesList + "]";
+ }
}
// TODO(b/117779333): support proto
@Override
public void dumpShort(@NonNull PrintWriter pw) {
synchronized (mLock) {
- pw.print("FrameworkResourcesServiceNamer: resId="); pw.print(mResourceId);
- pw.print(", numberTemps="); pw.print(mTemporaryServiceNames.size());
- pw.print(", enabledDefaults="); pw.print(mDefaultServicesDisabled.size());
+ pw.print("FrameworkResourcesServiceNamer: resId=");
+ pw.print(mStringResourceId);
+ pw.print(", numberTemps=");
+ pw.print(mTemporaryServiceNamesList.size());
+ pw.print(", enabledDefaults=");
+ pw.print(mDefaultServicesDisabled.size());
}
}
@@ -224,13 +285,17 @@
@Override
public void dumpShort(@NonNull PrintWriter pw, @UserIdInt int userId) {
synchronized (mLock) {
- final String temporaryName = mTemporaryServiceNames.get(userId);
- if (temporaryName != null) {
- pw.print("tmpName="); pw.print(temporaryName);
+ final String[] temporaryNames = mTemporaryServiceNamesList.get(userId);
+ if (temporaryNames != null) {
+ pw.print("tmpName=");
+ pw.print(Arrays.toString(temporaryNames));
final long ttl = mTemporaryServiceExpiration - SystemClock.elapsedRealtime();
- pw.print(" (expires in "); TimeUtils.formatDuration(ttl, pw); pw.print("), ");
+ pw.print(" (expires in ");
+ TimeUtils.formatDuration(ttl, pw);
+ pw.print("), ");
}
- pw.print("defaultName="); pw.print(getDefaultServiceName(userId));
+ pw.print("defaultName=");
+ pw.print(getDefaultServiceName(userId));
final boolean disabled = mDefaultServicesDisabled.get(userId);
pw.println(disabled ? " (disabled)" : " (enabled)");
}
diff --git a/services/core/java/com/android/server/infra/OWNERS b/services/core/java/com/android/server/infra/OWNERS
new file mode 100644
index 0000000..0466d8a
--- /dev/null
+++ b/services/core/java/com/android/server/infra/OWNERS
@@ -0,0 +1,3 @@
+# Bug component: 655446
+
+include /core/java/android/service/cloudsearch/OWNERS
diff --git a/services/core/java/com/android/server/infra/ServiceNameResolver.java b/services/core/java/com/android/server/infra/ServiceNameResolver.java
index e20c459..7d85fdb4 100644
--- a/services/core/java/com/android/server/infra/ServiceNameResolver.java
+++ b/services/core/java/com/android/server/infra/ServiceNameResolver.java
@@ -34,7 +34,7 @@
/**
* Listener for name changes.
*/
- public interface NameResolverListener {
+ interface NameResolverListener {
/**
* The name change callback.
@@ -64,6 +64,30 @@
String getDefaultServiceName(@UserIdInt int userId);
/**
+ * Gets the default list of names of the services for the given user.
+ *
+ * <p>Typically implemented by reading a Settings property or framework resource.
+ */
+ @Nullable
+ default String[] getDefaultServiceNameList(@UserIdInt int userId) {
+ if (isConfiguredInMultipleMode()) {
+ throw new UnsupportedOperationException("getting default service list not supported");
+ } else {
+ return new String[] { getDefaultServiceName(userId) };
+ }
+ }
+
+ /**
+ * Returns whether the resolver is configured to connect to multiple backend services.
+ * The default return type is false.
+ *
+ * <p>Typically implemented by reading a Settings property or framework resource.
+ */
+ default boolean isConfiguredInMultipleMode() {
+ return false;
+ }
+
+ /**
* Gets the current name of the service for the given user
*
* @return either the temporary name (set by
@@ -76,6 +100,18 @@
}
/**
+ * Gets the current name of the service for the given user
+ *
+ * @return either the temporary name (set by
+ * {@link #setTemporaryService(int, String, int)}, or the
+ * {@link #getDefaultServiceName(int) default name}.
+ */
+ @Nullable
+ default String[] getServiceNameList(@UserIdInt int userId) {
+ return getDefaultServiceNameList(userId);
+ }
+
+ /**
* Checks whether the current service is temporary for the given user.
*/
default boolean isTemporary(@SuppressWarnings("unused") @UserIdInt int userId) {
@@ -85,11 +121,11 @@
/**
* Temporarily sets the service implementation for the given user.
*
- * @param userId user handle
+ * @param userId user handle
* @param componentName name of the new component
- * @param durationMs how long the change will be valid (the service will be automatically reset
- * to the default component after this timeout expires).
- *
+ * @param durationMs how long the change will be valid (the service will be automatically
+ * reset
+ * to the default component after this timeout expires).
* @throws UnsupportedOperationException if not implemented.
*/
default void setTemporaryService(@UserIdInt int userId, @NonNull String componentName,
@@ -98,10 +134,24 @@
}
/**
+ * Temporarily sets the service implementation for the given user.
+ *
+ * @param userId user handle
+ * @param componentNames list of the names of the new component
+ * @param durationMs how long the change will be valid (the service will be automatically
+ * reset
+ * to the default component after this timeout expires).
+ * @throws UnsupportedOperationException if not implemented.
+ */
+ default void setTemporaryServices(@UserIdInt int userId, @NonNull String[] componentNames,
+ int durationMs) {
+ throw new UnsupportedOperationException("temporary user not supported");
+ }
+
+ /**
* Resets the temporary service implementation to the default component for the given user.
*
* @param userId user handle
- *
* @throws UnsupportedOperationException if not implemented.
*/
default void resetTemporaryService(@UserIdInt int userId) {
@@ -114,11 +164,11 @@
* <p>Typically used during CTS tests to make sure only the default service doesn't interfere
* with the test results.
*
- * @param userId user handle
+ * @param userId user handle
* @param enabled whether the default service should be used when the temporary service is not
- * set. If the service enabled state is already that value, the command is ignored and this
- * method return {@code false}.
- *
+ * set. If the service enabled state is already that value, the command is
+ * ignored and this
+ * method return {@code false}.
* @return whether the enabled state changed.
* @throws UnsupportedOperationException if not implemented.
*/
@@ -133,7 +183,6 @@
* with the test results.
*
* @param userId user handle
- *
* @throws UnsupportedOperationException if not implemented.
*/
default boolean isDefaultServiceEnabled(@UserIdInt int userId) {
diff --git a/services/core/java/com/android/server/location/geofence/GeofenceManager.java b/services/core/java/com/android/server/location/geofence/GeofenceManager.java
index 5093f5d..b6342a4 100644
--- a/services/core/java/com/android/server/location/geofence/GeofenceManager.java
+++ b/services/core/java/com/android/server/location/geofence/GeofenceManager.java
@@ -19,7 +19,6 @@
import static android.location.LocationManager.FUSED_PROVIDER;
import static android.location.LocationManager.KEY_PROXIMITY_ENTERING;
-import static com.android.internal.util.ConcurrentUtils.DIRECT_EXECUTOR;
import static com.android.server.location.LocationPermissions.PERMISSION_FINE;
import android.annotation.Nullable;
@@ -41,6 +40,7 @@
import android.util.ArraySet;
import com.android.internal.annotations.GuardedBy;
+import com.android.server.FgThread;
import com.android.server.PendingIntentUtils;
import com.android.server.location.LocationPermissions;
import com.android.server.location.injector.Injector;
@@ -396,7 +396,7 @@
protected boolean registerWithService(LocationRequest locationRequest,
Collection<GeofenceRegistration> registrations) {
getLocationManager().requestLocationUpdates(FUSED_PROVIDER, locationRequest,
- DIRECT_EXECUTOR, this);
+ FgThread.getExecutor(), this);
return true;
}
diff --git a/services/core/java/com/android/server/location/provider/LocationProviderManager.java b/services/core/java/com/android/server/location/provider/LocationProviderManager.java
index acbee11..721ef1e 100644
--- a/services/core/java/com/android/server/location/provider/LocationProviderManager.java
+++ b/services/core/java/com/android/server/location/provider/LocationProviderManager.java
@@ -201,18 +201,54 @@
@Override
public void deliverOnLocationChanged(LocationResult locationResult,
@Nullable IRemoteCallback onCompleteCallback) throws RemoteException {
- mListener.onLocationChanged(locationResult.asList(), onCompleteCallback);
+ try {
+ mListener.onLocationChanged(locationResult.asList(), onCompleteCallback);
+ } catch (RuntimeException e) {
+ // the only way a runtime exception can be thrown here is if the client is in the
+ // system server process (so that the binder call is executed directly, rather than
+ // asynchronously in another process), and the client is using a direct executor (so
+ // any client exceptions bubble directly back to us). we move any exception onto
+ // another thread so that it can't cause further problems
+ RuntimeException wrapper = new RuntimeException(e);
+ FgThread.getExecutor().execute(() -> {
+ throw wrapper;
+ });
+ }
}
@Override
public void deliverOnFlushComplete(int requestCode) throws RemoteException {
- mListener.onFlushComplete(requestCode);
+ try {
+ mListener.onFlushComplete(requestCode);
+ } catch (RuntimeException e) {
+ // the only way a runtime exception can be thrown here is if the client is in the
+ // system server process (so that the binder call is executed directly, rather than
+ // asynchronously in another process), and the client is using a direct executor (so
+ // any client exceptions bubble directly back to us). we move any exception onto
+ // another thread so that it can't cause further problems
+ RuntimeException wrapper = new RuntimeException(e);
+ FgThread.getExecutor().execute(() -> {
+ throw wrapper;
+ });
+ }
}
@Override
public void deliverOnProviderEnabledChanged(String provider, boolean enabled)
throws RemoteException {
- mListener.onProviderEnabledChanged(provider, enabled);
+ try {
+ mListener.onProviderEnabledChanged(provider, enabled);
+ } catch (RuntimeException e) {
+ // the only way a runtime exception can be thrown here is if the client is in the
+ // system server process (so that the binder call is executed directly, rather than
+ // asynchronously in another process), and the client is using a direct executor (so
+ // any client exceptions bubble directly back to us). we move any exception onto
+ // another thread so that it can't cause further problems
+ RuntimeException wrapper = new RuntimeException(e);
+ FgThread.getExecutor().execute(() -> {
+ throw wrapper;
+ });
+ }
}
}
@@ -294,10 +330,23 @@
throws RemoteException {
// ILocationCallback doesn't currently support completion callbacks
Preconditions.checkState(onCompleteCallback == null);
- if (locationResult != null) {
- mCallback.onLocation(locationResult.getLastLocation());
- } else {
- mCallback.onLocation(null);
+
+ try {
+ if (locationResult != null) {
+ mCallback.onLocation(locationResult.getLastLocation());
+ } else {
+ mCallback.onLocation(null);
+ }
+ } catch (RuntimeException e) {
+ // the only way a runtime exception can be thrown here is if the client is in the
+ // system server process (so that the binder call is executed directly, rather than
+ // asynchronously in another process), and the client is using a direct executor (so
+ // any client exceptions bubble directly back to us). we move any exception onto
+ // another thread so that it can't cause further problems
+ RuntimeException wrapper = new RuntimeException(e);
+ FgThread.getExecutor().execute(() -> {
+ throw wrapper;
+ });
}
}
diff --git a/services/core/java/com/android/server/pm/ComputerEngine.java b/services/core/java/com/android/server/pm/ComputerEngine.java
index 30ac1b8..ca3ee85 100644
--- a/services/core/java/com/android/server/pm/ComputerEngine.java
+++ b/services/core/java/com/android/server/pm/ComputerEngine.java
@@ -2161,8 +2161,8 @@
private String[] getPackagesForUidInternal(int uid, int callingUid) {
final boolean isCallerInstantApp = getInstantAppPackageName(callingUid) != null;
final int userId = UserHandle.getUserId(uid);
- if (Process.isSupplemental(uid)) {
- uid = getSupplementalProcessUid();
+ if (Process.isSdkSandboxUid(uid)) {
+ uid = getBaseSdkSandboxUid();
}
final int appId = UserHandle.getAppId(uid);
return getPackagesForUidInternalBody(callingUid, userId, appId, isCallerInstantApp);
@@ -2401,9 +2401,9 @@
}
public final boolean isCallerSameApp(String packageName, int uid) {
- if (Process.isSupplemental(uid)) {
+ if (Process.isSdkSandboxUid(uid)) {
return (packageName != null
- && packageName.equals(mService.getSupplementalProcessPackageName()));
+ && packageName.equals(mService.getSdkSandboxPackageName()));
}
AndroidPackage pkg = mPackages.get(packageName);
return pkg != null
@@ -4326,8 +4326,8 @@
if (getInstantAppPackageName(callingUid) != null) {
return null;
}
- if (Process.isSupplemental(uid)) {
- uid = getSupplementalProcessUid();
+ if (Process.isSdkSandboxUid(uid)) {
+ uid = getBaseSdkSandboxUid();
}
final int callingUserId = UserHandle.getUserId(callingUid);
final int appId = UserHandle.getAppId(uid);
@@ -4362,8 +4362,8 @@
final String[] names = new String[uids.length];
for (int i = uids.length - 1; i >= 0; i--) {
int uid = uids[i];
- if (Process.isSupplemental(uid)) {
- uid = getSupplementalProcessUid();
+ if (Process.isSdkSandboxUid(uid)) {
+ uid = getBaseSdkSandboxUid();
}
final int appId = UserHandle.getAppId(uid);
final Object obj = mSettings.getSettingBase(appId);
@@ -4411,8 +4411,8 @@
if (getInstantAppPackageName(callingUid) != null) {
return 0;
}
- if (Process.isSupplemental(uid)) {
- uid = getSupplementalProcessUid();
+ if (Process.isSdkSandboxUid(uid)) {
+ uid = getBaseSdkSandboxUid();
}
final int callingUserId = UserHandle.getUserId(callingUid);
final int appId = UserHandle.getAppId(uid);
@@ -4439,8 +4439,8 @@
if (getInstantAppPackageName(callingUid) != null) {
return 0;
}
- if (Process.isSupplemental(uid)) {
- uid = getSupplementalProcessUid();
+ if (Process.isSdkSandboxUid(uid)) {
+ uid = getBaseSdkSandboxUid();
}
final int callingUserId = UserHandle.getUserId(callingUid);
final int appId = UserHandle.getAppId(uid);
@@ -4466,8 +4466,8 @@
if (getInstantAppPackageName(Binder.getCallingUid()) != null) {
return false;
}
- if (Process.isSupplemental(uid)) {
- uid = getSupplementalProcessUid();
+ if (Process.isSdkSandboxUid(uid)) {
+ uid = getBaseSdkSandboxUid();
}
final int appId = UserHandle.getAppId(uid);
final Object obj = mSettings.getSettingBase(appId);
@@ -5597,8 +5597,8 @@
@Override
public int getUidTargetSdkVersion(int uid) {
- if (Process.isSupplemental(uid)) {
- uid = getSupplementalProcessUid();
+ if (Process.isSdkSandboxUid(uid)) {
+ uid = getBaseSdkSandboxUid();
}
final int appId = UserHandle.getAppId(uid);
final SettingBase settingBase = mSettings.getSettingBase(appId);
@@ -5628,8 +5628,8 @@
@Nullable
@Override
public ArrayMap<String, ProcessInfo> getProcessesForUid(int uid) {
- if (Process.isSupplemental(uid)) {
- uid = getSupplementalProcessUid();
+ if (Process.isSdkSandboxUid(uid)) {
+ uid = getBaseSdkSandboxUid();
}
final int appId = UserHandle.getAppId(uid);
final SettingBase settingBase = mSettings.getSettingBase(appId);
@@ -5661,8 +5661,8 @@
}
}
- private int getSupplementalProcessUid() {
- return getPackage(mService.getSupplementalProcessPackageName()).getUid();
+ private int getBaseSdkSandboxUid() {
+ return getPackage(mService.getSdkSandboxPackageName()).getUid();
}
@Nullable
diff --git a/services/core/java/com/android/server/pm/DexOptHelper.java b/services/core/java/com/android/server/pm/DexOptHelper.java
index 53eb9cf..c832693 100644
--- a/services/core/java/com/android/server/pm/DexOptHelper.java
+++ b/services/core/java/com/android/server/pm/DexOptHelper.java
@@ -460,7 +460,8 @@
| DexoptOptions.DEXOPT_CHECK_FOR_PROFILES_UPDATES
| DexoptOptions.DEXOPT_BOOT_COMPLETE
| (force ? DexoptOptions.DEXOPT_FORCE : 0);
- return performDexOpt(new DexoptOptions(packageName, compilerFilter, flags));
+ return performDexOpt(new DexoptOptions(packageName, REASON_CMDLINE,
+ compilerFilter, null /* splitName */, flags));
}
// Sort apps by importance for dexopt ordering. Important apps are given
diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java
index c05faf1..0602f3e 100644
--- a/services/core/java/com/android/server/pm/PackageManagerService.java
+++ b/services/core/java/com/android/server/pm/PackageManagerService.java
@@ -247,8 +247,8 @@
import com.android.server.pm.verify.domain.DomainVerificationService;
import com.android.server.pm.verify.domain.proxy.DomainVerificationProxy;
import com.android.server.pm.verify.domain.proxy.DomainVerificationProxyV1;
+import com.android.server.sdksandbox.SdkSandboxManagerLocal;
import com.android.server.storage.DeviceStorageMonitorInternal;
-import com.android.server.supplementalprocess.SupplementalProcessManagerLocal;
import com.android.server.utils.SnapshotCache;
import com.android.server.utils.TimingsTraceAndSlog;
import com.android.server.utils.Watchable;
@@ -934,7 +934,7 @@
final @Nullable String mOverlayConfigSignaturePackage;
final @Nullable String mRecentsPackage;
final @Nullable String mAmbientContextDetectionPackage;
- private final @NonNull String mRequiredSupplementalProcessPackage;
+ private final @NonNull String mRequiredSdkSandboxPackage;
@GuardedBy("mLock")
private final PackageUsage mPackageUsage = new PackageUsage();
@@ -1667,7 +1667,7 @@
mSharedSystemSharedLibraryPackageName = testParams.sharedSystemSharedLibraryPackageName;
mOverlayConfigSignaturePackage = testParams.overlayConfigSignaturePackage;
mResolveComponentName = testParams.resolveComponentName;
- mRequiredSupplementalProcessPackage = testParams.requiredSupplementalProcessPackage;
+ mRequiredSdkSandboxPackage = testParams.requiredSdkSandboxPackage;
mLiveComputer = createLiveComputer();
mSnapshotComputer = null;
@@ -2141,8 +2141,8 @@
getPackageInfo(mRequiredPermissionControllerPackage, 0,
UserHandle.USER_SYSTEM).getLongVersionCode());
- // Resolve the supplemental process
- mRequiredSupplementalProcessPackage = getRequiredSupplementalProcessPackageName();
+ // Resolve the sdk sandbox package
+ mRequiredSdkSandboxPackage = getRequiredSdkSandboxPackageName();
// Initialize InstantAppRegistry's Instant App list for all users.
for (AndroidPackage pkg : mPackages.values()) {
@@ -3143,8 +3143,8 @@
}
@Override
- public String getSupplementalProcessPackageName() {
- return mRequiredSupplementalProcessPackage;
+ public String getSdkSandboxPackageName() {
+ return mRequiredSdkSandboxPackage;
}
String getPackageInstallerPackageName() {
@@ -5458,8 +5458,8 @@
}
}
- private @NonNull String getRequiredSupplementalProcessPackageName() {
- final Intent intent = new Intent(SupplementalProcessManagerLocal.SERVICE_INTERFACE);
+ private @NonNull String getRequiredSdkSandboxPackageName() {
+ final Intent intent = new Intent(SdkSandboxManagerLocal.SERVICE_INTERFACE);
final List<ResolveInfo> matches = queryIntentServicesInternal(
intent,
@@ -5471,7 +5471,7 @@
if (matches.size() == 1) {
return matches.get(0).getComponentInfo().packageName;
} else {
- throw new RuntimeException("There should exactly one supplemental process; found "
+ throw new RuntimeException("There should exactly one sdk sandbox package; found "
+ matches.size() + ": matches=" + matches);
}
}
diff --git a/services/core/java/com/android/server/pm/PackageManagerServiceTestParams.java b/services/core/java/com/android/server/pm/PackageManagerServiceTestParams.java
index d12c826..5bdda0b 100644
--- a/services/core/java/com/android/server/pm/PackageManagerServiceTestParams.java
+++ b/services/core/java/com/android/server/pm/PackageManagerServiceTestParams.java
@@ -89,7 +89,7 @@
public @Nullable String defaultTextClassifierPackage;
public @Nullable String systemTextClassifierPackage;
public @Nullable String overlayConfigSignaturePackage;
- public @NonNull String requiredSupplementalProcessPackage;
+ public @NonNull String requiredSdkSandboxPackage;
public ViewCompiler viewCompiler;
public @Nullable String retailDemoPackage;
public @Nullable String recentsPackage;
diff --git a/services/core/java/com/android/server/pm/Settings.java b/services/core/java/com/android/server/pm/Settings.java
index 394c8fb..3e5ab1e 100644
--- a/services/core/java/com/android/server/pm/Settings.java
+++ b/services/core/java/com/android/server/pm/Settings.java
@@ -3906,13 +3906,17 @@
} else if (tagName.equals(TAG_PERMISSIONS)) {
final LegacyPermissionState legacyState;
if (packageSetting.hasSharedUser()) {
- legacyState = getSettingLPr(
- packageSetting.getSharedUserAppId()).getLegacyPermissionState();
+ final SettingBase sharedUserSettings = getSettingLPr(
+ packageSetting.getSharedUserAppId());
+ legacyState = sharedUserSettings != null
+ ? sharedUserSettings.getLegacyPermissionState() : null;
} else {
legacyState = packageSetting.getLegacyPermissionState();
}
- readInstallPermissionsLPr(parser, legacyState, users);
- packageSetting.setInstallPermissionsFixed(true);
+ if (legacyState != null) {
+ readInstallPermissionsLPr(parser, legacyState, users);
+ packageSetting.setInstallPermissionsFixed(true);
+ }
} else if (tagName.equals("proper-signing-keyset")) {
long id = parser.getAttributeLong(null, "identifier");
Integer refCt = mKeySetRefs.get(id);
diff --git a/services/core/java/com/android/server/policy/PermissionPolicyService.java b/services/core/java/com/android/server/policy/PermissionPolicyService.java
index c637c67..f2ce0d4 100644
--- a/services/core/java/com/android/server/policy/PermissionPolicyService.java
+++ b/services/core/java/com/android/server/policy/PermissionPolicyService.java
@@ -34,6 +34,7 @@
import android.app.ActivityTaskManager;
import android.app.AppOpsManager;
import android.app.AppOpsManagerInternal;
+import android.app.KeyguardManager;
import android.app.TaskInfo;
import android.app.compat.CompatChanges;
import android.compat.annotation.ChangeId;
@@ -150,6 +151,7 @@
private Context mContext;
private PackageManagerInternal mPackageManagerInternal;
private NotificationManagerInternal mNotificationManager;
+ private final KeyguardManager mKeyguardManager;
private final PackageManager mPackageManager;
public PermissionPolicyService(@NonNull Context context) {
@@ -157,6 +159,7 @@
mContext = context;
mPackageManager = context.getPackageManager();
+ mKeyguardManager = context.getSystemService(KeyguardManager.class);
LocalServices.addService(PermissionPolicyInternal.class, new Internal());
}
@@ -1046,12 +1049,21 @@
}
@Override
- public void onActivityLaunched(TaskInfo taskInfo, ActivityInfo activityInfo) {
- super.onActivityLaunched(taskInfo, activityInfo);
- clearNotificationReviewFlagsIfNeeded(activityInfo.packageName,
- UserHandle.of(taskInfo.userId));
- showNotificationPromptIfNeeded(activityInfo.packageName,
- taskInfo.userId, taskInfo.taskId);
+ public void onActivityLaunched(TaskInfo taskInfo, ActivityInfo activityInfo,
+ ActivityInterceptorInfo info) {
+ super.onActivityLaunched(taskInfo, activityInfo, info);
+ if (!shouldShowNotificationDialogOrClearFlags(info.intent,
+ info.checkedOptions)) {
+ return;
+ }
+ UserHandle user = UserHandle.of(taskInfo.userId);
+ if (CompatChanges.isChangeEnabled(NOTIFICATION_PERM_CHANGE_ID,
+ activityInfo.packageName, user)) {
+ clearNotificationReviewFlagsIfNeeded(activityInfo.packageName, user);
+ } else {
+ showNotificationPromptIfNeeded(activityInfo.packageName,
+ taskInfo.userId, taskInfo.taskId);
+ }
}
};
@@ -1092,10 +1104,28 @@
launchNotificationPermissionRequestDialog(packageName, user, taskId);
}
+ /**
+ * Determine if we should show a notification dialog, or clear the REVIEW_REQUIRED flag,
+ * from a particular package for a particular intent. Returns true if:
+ * 1. The isEligibleForLegacyPermissionPrompt ActivityOption is set, or
+ * 2. The intent is a launcher intent (action is ACTION_MAIN, category is LAUNCHER)
+ */
+ private boolean shouldShowNotificationDialogOrClearFlags(Intent intent,
+ ActivityOptions options) {
+ if ((options != null && options.isEligibleForLegacyPermissionPrompt())) {
+ return true;
+ }
+
+ return Intent.ACTION_MAIN.equals(intent.getAction())
+ && intent.getCategories() != null
+ && (intent.getCategories().contains(Intent.CATEGORY_LAUNCHER)
+ || intent.getCategories().contains(Intent.CATEGORY_LEANBACK_LAUNCHER)
+ || intent.getCategories().contains(Intent.CATEGORY_CAR_LAUNCHER));
+ }
+
private void clearNotificationReviewFlagsIfNeeded(String packageName, UserHandle user) {
- if (!CompatChanges.isChangeEnabled(NOTIFICATION_PERM_CHANGE_ID, packageName, user)
- || ((mPackageManager.getPermissionFlags(POST_NOTIFICATIONS, packageName, user)
- & FLAG_PERMISSION_REVIEW_REQUIRED) == 0)) {
+ if ((mPackageManager.getPermissionFlags(POST_NOTIFICATIONS, packageName, user)
+ & FLAG_PERMISSION_REVIEW_REQUIRED) == 0) {
return;
}
try {
@@ -1210,8 +1240,8 @@
}
if (!pkg.getRequestedPermissions().contains(POST_NOTIFICATIONS)
- || CompatChanges.isChangeEnabled(NOTIFICATION_PERM_CHANGE_ID,
- pkg.getPackageName(), user)) {
+ || CompatChanges.isChangeEnabled(NOTIFICATION_PERM_CHANGE_ID, pkgName, user)
+ || mKeyguardManager.isKeyguardLocked()) {
return false;
}
@@ -1220,7 +1250,7 @@
mNotificationManager = LocalServices.getService(NotificationManagerInternal.class);
}
boolean hasCreatedNotificationChannels = mNotificationManager
- .getNumNotificationChannelsForPackage(pkg.getPackageName(), uid, true) > 0;
+ .getNumNotificationChannelsForPackage(pkgName, uid, true) > 0;
int flags = mPackageManager.getPermissionFlags(POST_NOTIFICATIONS, pkgName, user);
boolean explicitlySet = (flags & PermissionManager.EXPLICIT_SET_FLAGS) != 0;
boolean needsReview = (flags & FLAG_PERMISSION_REVIEW_REQUIRED) != 0;
diff --git a/services/core/java/com/android/server/vibrator/VibrationSettings.java b/services/core/java/com/android/server/vibrator/VibrationSettings.java
index 6c5d952..b05b44b 100644
--- a/services/core/java/com/android/server/vibrator/VibrationSettings.java
+++ b/services/core/java/com/android/server/vibrator/VibrationSettings.java
@@ -34,6 +34,7 @@
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
+import android.content.pm.PackageManagerInternal;
import android.content.res.Resources;
import android.database.ContentObserver;
import android.media.AudioManager;
@@ -42,6 +43,7 @@
import android.os.PowerManager;
import android.os.PowerManagerInternal;
import android.os.PowerSaveState;
+import android.os.Process;
import android.os.RemoteException;
import android.os.UserHandle;
import android.os.VibrationAttributes;
@@ -106,6 +108,19 @@
*/
private static final int VIBRATE_ON_DISABLED_USAGE_ALLOWED = USAGE_ACCESSIBILITY;
+ /**
+ * Set of usages allowed for vibrations from system packages when the screen goes off.
+ *
+ * <p>Some examples are touch and hardware feedback, and physical emulation. When the system is
+ * playing one of these usages during the screen off event then the vibration will not be
+ * cancelled by the service.
+ */
+ private static final Set<Integer> SYSTEM_VIBRATION_SCREEN_OFF_USAGE_ALLOWLIST = new HashSet<>(
+ Arrays.asList(
+ USAGE_TOUCH,
+ USAGE_PHYSICAL_EMULATION,
+ USAGE_HARDWARE_FEEDBACK));
+
/** Listener for changes on vibration settings. */
interface OnVibratorSettingsChanged {
/** Callback triggered when any of the vibrator settings change. */
@@ -114,6 +129,7 @@
private final Object mLock = new Object();
private final Context mContext;
+ private final String mSystemUiPackage;
private final SettingsObserver mSettingObserver;
@VisibleForTesting
final UidObserver mUidObserver;
@@ -151,6 +167,9 @@
mUidObserver = new UidObserver();
mUserReceiver = new UserObserver();
+ mSystemUiPackage = LocalServices.getService(PackageManagerInternal.class)
+ .getSystemUiServiceComponent().getPackageName();
+
VibrationEffect clickEffect = createEffectFromResource(
com.android.internal.R.array.config_virtualKeyVibePattern);
VibrationEffect doubleClickEffect = createEffectFromResource(
@@ -344,27 +363,42 @@
}
/**
+ * Check if given vibration should be cancelled by the service when the screen goes off.
+ *
+ * <p>When the system is entering a non-interactive state, we want to cancel vibrations in case
+ * a misbehaving app has abandoned them. However, it may happen that the system is currently
+ * playing haptic feedback as part of the transition. So we don't cancel system vibrations of
+ * usages like touch and hardware feedback, and physical emulation.
+ *
+ * @return true if the vibration should be cancelled when the screen goes off, false otherwise.
+ */
+ public boolean shouldCancelVibrationOnScreenOff(int uid, String opPkg,
+ @VibrationAttributes.Usage int usage) {
+ if (!SYSTEM_VIBRATION_SCREEN_OFF_USAGE_ALLOWLIST.contains(usage)) {
+ // Usages not allowed even for system vibrations should always be cancelled.
+ return true;
+ }
+ // Only allow vibrations from System packages to continue vibrating when the screen goes off
+ return uid != Process.SYSTEM_UID && uid != 0 && !mSystemUiPackage.equals(opPkg);
+ }
+
+ /**
* Return {@code true} if the device should vibrate for current ringer mode.
*
* <p>This checks the current {@link AudioManager#getRingerModeInternal()} against user settings
- * for touch and ringtone usages only. All other usages are allowed by this method.
+ * for ringtone usage only. All other usages are allowed by this method.
*/
@GuardedBy("mLock")
private boolean shouldVibrateForRingerModeLocked(@VibrationAttributes.Usage int usageHint) {
+ if (usageHint != USAGE_RINGTONE) {
+ // Only ringtone vibrations are disabled when phone is on silent mode.
+ return true;
+ }
// If audio manager was not loaded yet then assume most restrictive mode.
int ringerMode = (mAudioManager == null)
? AudioManager.RINGER_MODE_SILENT
: mAudioManager.getRingerModeInternal();
-
- switch (usageHint) {
- case USAGE_TOUCH:
- case USAGE_RINGTONE:
- // Touch feedback and ringtone disabled when phone is on silent mode.
- return ringerMode != AudioManager.RINGER_MODE_SILENT;
- default:
- // All other usages ignore ringer mode settings.
- return true;
- }
+ return ringerMode != AudioManager.RINGER_MODE_SILENT;
}
/** Updates all vibration settings and triggers registered listeners. */
diff --git a/services/core/java/com/android/server/vibrator/VibratorManagerService.java b/services/core/java/com/android/server/vibrator/VibratorManagerService.java
index 01f9d0b9..94d0a7b 100644
--- a/services/core/java/com/android/server/vibrator/VibratorManagerService.java
+++ b/services/core/java/com/android/server/vibrator/VibratorManagerService.java
@@ -28,7 +28,6 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
-import android.content.pm.PackageManagerInternal;
import android.hardware.vibrator.IVibrator;
import android.os.BatteryStats;
import android.os.Binder;
@@ -62,7 +61,6 @@
import com.android.internal.app.IBatteryStats;
import com.android.internal.util.DumpUtils;
import com.android.internal.util.FrameworkStatsLog;
-import com.android.server.LocalServices;
import com.android.server.SystemService;
import libcore.util.NativeAllocationRegistry;
@@ -120,7 +118,6 @@
private final Object mLock = new Object();
private final Context mContext;
- private final String mSystemUiPackage;
private final PowerManager.WakeLock mWakeLock;
private final IBatteryStats mBatteryStatsService;
private final Handler mHandler;
@@ -153,17 +150,12 @@
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
synchronized (mLock) {
- // When the system is entering a non-interactive state, we want
- // to cancel vibrations in case a misbehaving app has abandoned
- // them. However it may happen that the system is currently playing
- // haptic feedback as part of the transition. So we don't cancel
- // system vibrations.
- if (mNextVibration != null
- && !isSystemHapticFeedback(mNextVibration.getVibration())) {
+ // When the system is entering a non-interactive state, we want to cancel
+ // vibrations in case a misbehaving app has abandoned them.
+ if (shouldCancelOnScreenOffLocked(mNextVibration)) {
clearNextVibrationLocked(Vibration.Status.CANCELLED);
}
- if (mCurrentVibration != null
- && !isSystemHapticFeedback(mCurrentVibration.getVibration())) {
+ if (shouldCancelOnScreenOffLocked(mCurrentVibration)) {
mCurrentVibration.cancel();
}
}
@@ -203,9 +195,6 @@
com.android.internal.R.integer.config_previousVibrationsDumpLimit);
mVibratorManagerRecords = new VibratorManagerRecords(dumpLimit);
- mSystemUiPackage = LocalServices.getService(PackageManagerInternal.class)
- .getSystemUiServiceComponent().getPackageName();
-
mBatteryStatsService = injector.getBatteryStatsService();
mAppOps = mContext.getSystemService(AppOpsManager.class);
@@ -1074,11 +1063,14 @@
== PackageManager.PERMISSION_GRANTED;
}
- private boolean isSystemHapticFeedback(Vibration vib) {
- if (vib.attrs.getUsage() != VibrationAttributes.USAGE_TOUCH) {
+ @GuardedBy("mLock")
+ private boolean shouldCancelOnScreenOffLocked(@Nullable VibrationThread vibrationThread) {
+ if (vibrationThread == null) {
return false;
}
- return vib.uid == Process.SYSTEM_UID || vib.uid == 0 || mSystemUiPackage.equals(vib.opPkg);
+ Vibration vib = vibrationThread.getVibration();
+ return mVibrationSettings.shouldCancelVibrationOnScreenOff(
+ vib.uid, vib.opPkg, vib.attrs.getUsage());
}
@GuardedBy("mLock")
diff --git a/services/core/java/com/android/server/wm/AccessibilityController.java b/services/core/java/com/android/server/wm/AccessibilityController.java
index 57f77d5..8f703c5 100644
--- a/services/core/java/com/android/server/wm/AccessibilityController.java
+++ b/services/core/java/com/android/server/wm/AccessibilityController.java
@@ -263,8 +263,6 @@
FLAGS_MAGNIFICATION_CALLBACK | FLAGS_WINDOWS_FOR_ACCESSIBILITY_CALLBACK,
"displayId=" + displayId + "; spec={" + spec + "}");
}
- mAccessibilityWindowsPopulator.setMagnificationSpec(displayId, spec);
-
final DisplayMagnifier displayMagnifier = mDisplayMagnifiers.get(displayId);
if (displayMagnifier != null) {
displayMagnifier.setMagnificationSpec(spec);
@@ -456,6 +454,19 @@
return null;
}
+ boolean getMagnificationSpecForDisplay(int displayId, MagnificationSpec outSpec) {
+ if (mAccessibilityTracing.isTracingEnabled(FLAGS_MAGNIFICATION_CALLBACK)) {
+ mAccessibilityTracing.logTrace(TAG + ".getMagnificationSpecForDisplay",
+ FLAGS_MAGNIFICATION_CALLBACK, "displayId=" + displayId);
+ }
+ final DisplayMagnifier displayMagnifier = mDisplayMagnifiers.get(displayId);
+ if (displayMagnifier == null) {
+ return false;
+ }
+
+ return displayMagnifier.getMagnificationSpec(outSpec);
+ }
+
boolean hasCallbacks() {
if (mAccessibilityTracing.isTracingEnabled(FLAGS_MAGNIFICATION_CALLBACK
| FLAGS_WINDOWS_FOR_ACCESSIBILITY_CALLBACK)) {
@@ -757,6 +768,25 @@
return spec;
}
+ boolean getMagnificationSpec(MagnificationSpec outSpec) {
+ if (mAccessibilityTracing.isTracingEnabled(FLAGS_MAGNIFICATION_CALLBACK)) {
+ mAccessibilityTracing.logTrace(LOG_TAG + ".getMagnificationSpec",
+ FLAGS_MAGNIFICATION_CALLBACK);
+ }
+ MagnificationSpec spec = mMagnifedViewport.getMagnificationSpec();
+ if (spec == null) {
+ return false;
+ }
+
+ outSpec.setTo(spec);
+ if (mAccessibilityTracing.isTracingEnabled(FLAGS_MAGNIFICATION_CALLBACK)) {
+ mAccessibilityTracing.logTrace(LOG_TAG + ".getMagnificationSpec",
+ FLAGS_MAGNIFICATION_CALLBACK, "outSpec={" + outSpec + "}");
+ }
+
+ return true;
+ }
+
void getMagnificationRegion(Region outMagnificationRegion) {
if (mAccessibilityTracing.isTracingEnabled(FLAGS_MAGNIFICATION_CALLBACK)) {
mAccessibilityTracing.logTrace(LOG_TAG + ".getMagnificationRegion",
diff --git a/services/core/java/com/android/server/wm/AccessibilityWindowsPopulator.java b/services/core/java/com/android/server/wm/AccessibilityWindowsPopulator.java
index 43317ad..c0fb83b 100644
--- a/services/core/java/com/android/server/wm/AccessibilityWindowsPopulator.java
+++ b/services/core/java/com/android/server/wm/AccessibilityWindowsPopulator.java
@@ -41,9 +41,7 @@
import com.android.internal.annotations.GuardedBy;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
/**
* This class is the accessibility windows population adapter.
@@ -70,24 +68,13 @@
private final SparseArray<Matrix> mMagnificationSpecInverseMatrix = new SparseArray<>();
@GuardedBy("mLock")
private final SparseArray<DisplayInfo> mDisplayInfos = new SparseArray<>();
- private final SparseArray<MagnificationSpec> mCurrentMagnificationSpec = new SparseArray<>();
- @GuardedBy("mLock")
- private final SparseArray<MagnificationSpec> mPreviousMagnificationSpec = new SparseArray<>();
@GuardedBy("mLock")
private final List<InputWindowHandle> mVisibleWindows = new ArrayList<>();
@GuardedBy("mLock")
private boolean mWindowsNotificationEnabled = false;
- @GuardedBy("mLock")
- private final Map<IBinder, Matrix> mWindowsTransformMatrixMap = new HashMap<>();
private final Object mLock = new Object();
private final Handler mHandler;
- private final Matrix mTempMatrix1 = new Matrix();
- private final Matrix mTempMatrix2 = new Matrix();
- private final float[] mTempFloat1 = new float[9];
- private final float[] mTempFloat2 = new float[9];
- private final float[] mTempFloat3 = new float[9];
-
AccessibilityWindowsPopulator(WindowManagerService service,
AccessibilityController accessibilityController) {
mService = service;
@@ -145,55 +132,28 @@
@Override
public void onWindowInfosChanged(InputWindowHandle[] windowHandles,
DisplayInfo[] displayInfos) {
- final List<InputWindowHandle> tempVisibleWindows = new ArrayList<>();
-
- for (InputWindowHandle window : windowHandles) {
- if (window.visible && window.getWindow() != null) {
- tempVisibleWindows.add(window);
- }
- }
- final HashMap<IBinder, Matrix> windowsTransformMatrixMap =
- getWindowsTransformMatrix(tempVisibleWindows);
-
synchronized (mLock) {
- mWindowsTransformMatrixMap.clear();
- mWindowsTransformMatrixMap.putAll(windowsTransformMatrixMap);
-
mVisibleWindows.clear();
- mVisibleWindows.addAll(tempVisibleWindows);
+ for (InputWindowHandle window : windowHandles) {
+ if (window.visible && window.getWindow() != null) {
+ mVisibleWindows.add(window);
+ }
+ }
mDisplayInfos.clear();
for (final DisplayInfo displayInfo : displayInfos) {
mDisplayInfos.put(displayInfo.mDisplayId, displayInfo);
}
- if (!mHandler.hasMessages(
- MyHandler.MESSAGE_NOTIFY_WINDOWS_CHANGED_BY_TIMEOUT)) {
- mHandler.sendEmptyMessageDelayed(
- MyHandler.MESSAGE_NOTIFY_WINDOWS_CHANGED_BY_TIMEOUT,
- WINDOWS_CHANGED_NOTIFICATION_MAX_DURATION_TIMES_MS);
- }
- populateVisibleWindowHandlesAndNotifyWindowsChangeIfNeeded();
- }
- }
-
- private HashMap<IBinder, Matrix> getWindowsTransformMatrix(List<InputWindowHandle> windows) {
- synchronized (mService.mGlobalLock) {
- final HashMap<IBinder, Matrix> windowsTransformMatrixMap = new HashMap<>();
-
- for (InputWindowHandle inputWindowHandle : windows) {
- final IWindow iWindow = inputWindowHandle.getWindow();
- final WindowState windowState = iWindow != null ? mService.mWindowMap.get(
- iWindow.asBinder()) : null;
-
- if (windowState != null && windowState.shouldMagnify()) {
- final Matrix transformMatrix = new Matrix();
- windowState.getTransformationMatrix(sTempFloats, transformMatrix);
- windowsTransformMatrixMap.put(iWindow.asBinder(), transformMatrix);
+ if (mWindowsNotificationEnabled) {
+ if (!mHandler.hasMessages(
+ MyHandler.MESSAGE_NOTIFY_WINDOWS_CHANGED_BY_TIMEOUT)) {
+ mHandler.sendEmptyMessageDelayed(
+ MyHandler.MESSAGE_NOTIFY_WINDOWS_CHANGED_BY_TIMEOUT,
+ WINDOWS_CHANGED_NOTIFICATION_MAX_DURATION_TIMES_MS);
}
+ populateVisibleWindowHandlesAndNotifyWindowsChangeIfNeededLocked();
}
-
- return windowsTransformMatrixMap;
}
}
@@ -211,43 +171,14 @@
}
mWindowsNotificationEnabled = register;
if (mWindowsNotificationEnabled) {
- populateVisibleWindowHandlesAndNotifyWindowsChangeIfNeeded();
+ populateVisibleWindowHandlesAndNotifyWindowsChangeIfNeededLocked();
} else {
releaseResources();
}
}
}
- /**
- * Sets the magnification spec for calculating the window bounds of all windows
- * reported from the surface flinger in the magnifying.
- *
- * @param displayId The display Id.
- * @param spec THe magnification spec.
- */
- public void setMagnificationSpec(int displayId, MagnificationSpec spec) {
- synchronized (mLock) {
- MagnificationSpec currentMagnificationSpec = mCurrentMagnificationSpec.get(displayId);
- if (currentMagnificationSpec == null) {
- currentMagnificationSpec = new MagnificationSpec();
- currentMagnificationSpec.setTo(spec);
- mCurrentMagnificationSpec.put(displayId, currentMagnificationSpec);
-
- return;
- }
-
- MagnificationSpec previousMagnificationSpec = mPreviousMagnificationSpec.get(displayId);
- if (previousMagnificationSpec == null) {
- previousMagnificationSpec = new MagnificationSpec();
- mPreviousMagnificationSpec.put(displayId, previousMagnificationSpec);
- }
- previousMagnificationSpec.setTo(currentMagnificationSpec);
- currentMagnificationSpec.setTo(spec);
- }
- }
-
- @GuardedBy("mLock")
- private void populateVisibleWindowHandlesAndNotifyWindowsChangeIfNeeded() {
+ private void populateVisibleWindowHandlesAndNotifyWindowsChangeIfNeededLocked() {
final SparseArray<List<InputWindowHandle>> tempWindowHandleList = new SparseArray<>();
for (final InputWindowHandle windowHandle : mVisibleWindows) {
@@ -257,15 +188,15 @@
if (inputWindowHandles == null) {
inputWindowHandles = new ArrayList<>();
tempWindowHandleList.put(windowHandle.displayId, inputWindowHandles);
+ generateMagnificationSpecInverseMatrixLocked(windowHandle.displayId);
}
inputWindowHandles.add(windowHandle);
}
- findMagnificationSpecInverseMatrixIfNeeded(tempWindowHandleList);
final List<Integer> displayIdsForWindowsChanged = new ArrayList<>();
- getDisplaysForWindowsChanged(displayIdsForWindowsChanged, tempWindowHandleList,
- mInputWindowHandlesOnDisplays);
+ getDisplaysForWindowsChangedLocked(displayIdsForWindowsChanged, tempWindowHandleList,
+ mInputWindowHandlesOnDisplays);
// Clones all windows from the callback of the surface flinger.
mInputWindowHandlesOnDisplays.clear();
for (int i = 0; i < tempWindowHandleList.size(); i++) {
@@ -273,7 +204,7 @@
mInputWindowHandlesOnDisplays.put(displayId, tempWindowHandleList.get(displayId));
}
- if (!displayIdsForWindowsChanged.isEmpty()) {
+ if (displayIdsForWindowsChanged.size() > 0) {
if (!mHandler.hasMessages(MyHandler.MESSAGE_NOTIFY_WINDOWS_CHANGED)) {
mHandler.obtainMessage(MyHandler.MESSAGE_NOTIFY_WINDOWS_CHANGED,
displayIdsForWindowsChanged).sendToTarget();
@@ -286,8 +217,7 @@
SURFACE_FLINGER_CALLBACK_WINDOWS_STABLE_TIMES_MS);
}
- @GuardedBy("mLock")
- private static void getDisplaysForWindowsChanged(List<Integer> outDisplayIdsForWindowsChanged,
+ private void getDisplaysForWindowsChangedLocked(List<Integer> outDisplayIdsForWindowsChanged,
SparseArray<List<InputWindowHandle>> newWindowsList,
SparseArray<List<InputWindowHandle>> oldWindowsList) {
for (int i = 0; i < newWindowsList.size(); i++) {
@@ -295,14 +225,13 @@
final List<InputWindowHandle> newWindows = newWindowsList.get(displayId);
final List<InputWindowHandle> oldWindows = oldWindowsList.get(displayId);
- if (hasWindowsChanged(newWindows, oldWindows)) {
+ if (hasWindowsChangedLocked(newWindows, oldWindows)) {
outDisplayIdsForWindowsChanged.add(displayId);
}
}
}
- @GuardedBy("mLock")
- private static boolean hasWindowsChanged(List<InputWindowHandle> newWindows,
+ private boolean hasWindowsChangedLocked(List<InputWindowHandle> newWindows,
List<InputWindowHandle> oldWindows) {
if (oldWindows == null || oldWindows.size() != newWindows.size()) {
return true;
@@ -324,195 +253,34 @@
return false;
}
- @GuardedBy("mLock")
- private void findMagnificationSpecInverseMatrixIfNeeded(SparseArray<List<InputWindowHandle>>
- windowHandleList) {
- MagnificationSpec currentMagnificationSpec;
- MagnificationSpec previousMagnificationSpec;
- for (int i = 0; i < windowHandleList.size(); i++) {
- final int displayId = windowHandleList.keyAt(i);
- List<InputWindowHandle> inputWindowHandles = windowHandleList.get(displayId);
-
- final MagnificationSpec currentSpec = mCurrentMagnificationSpec.get(displayId);
- if (currentSpec == null) {
- continue;
- }
- currentMagnificationSpec = new MagnificationSpec();
- currentMagnificationSpec.setTo(currentSpec);
-
- final MagnificationSpec previousSpec = mPreviousMagnificationSpec.get(displayId);
-
- if (previousSpec == null) {
- final Matrix inverseMatrixForCurrentSpec = new Matrix();
- generateInverseMatrix(currentMagnificationSpec, inverseMatrixForCurrentSpec);
- mMagnificationSpecInverseMatrix.put(displayId, inverseMatrixForCurrentSpec);
- continue;
- }
- previousMagnificationSpec = new MagnificationSpec();
- previousMagnificationSpec.setTo(previousSpec);
-
- generateInverseMatrixBasedOnProperMagnificationSpecForDisplay(inputWindowHandles,
- currentMagnificationSpec, previousMagnificationSpec);
+ private void generateMagnificationSpecInverseMatrixLocked(int displayId) {
+ MagnificationSpec spec = new MagnificationSpec();
+ if (!mAccessibilityController.getMagnificationSpecForDisplay(displayId, spec)) {
+ mMagnificationSpecInverseMatrix.remove(displayId);
+ return;
}
- }
-
- @GuardedBy("mLock")
- private void generateInverseMatrixBasedOnProperMagnificationSpecForDisplay(
- List<InputWindowHandle> inputWindowHandles, MagnificationSpec currentMagnificationSpec,
- MagnificationSpec previousMagnificationSpec) {
- // To decrease the counts of holding the WindowManagerService#mGlogalLock in
- // the method, getWindowTransformMatrix(), this for loop begins from the bottom
- // to top of the z-order windows.
- for (int index = inputWindowHandles.size() - 1; index >= 0; index--) {
- final Matrix windowTransformMatrix = mTempMatrix2;
- final InputWindowHandle windowHandle = inputWindowHandles.get(index);
- final IBinder iBinder = windowHandle.getWindow().asBinder();
-
- if (getWindowTransformMatrix(iBinder, windowTransformMatrix)) {
- generateMagnificationSpecInverseMatrix(windowHandle, currentMagnificationSpec,
- previousMagnificationSpec, windowTransformMatrix);
-
- break;
- }
- }
- }
-
- @GuardedBy("mLock")
- private boolean getWindowTransformMatrix(IBinder iBinder, Matrix outTransform) {
- final Matrix windowMatrix = iBinder != null
- ? mWindowsTransformMatrixMap.get(iBinder) : null;
-
- if (windowMatrix == null) {
- return false;
- }
- outTransform.set(windowMatrix);
-
- return true;
- }
-
- /**
- * Generates the inverse matrix based on the proper magnification spec.
- * The magnification spec associated with the InputWindowHandle might not the current
- * spec set by WM, which might be the previous one. To find the appropriate spec,
- * we store two consecutive magnification specs, and found out which one is the proper
- * one closing the identity matrix for generating the inverse matrix.
- *
- * @param inputWindowHandle The window from the surface flinger.
- * @param currentMagnificationSpec The current magnification spec.
- * @param previousMagnificationSpec The previous magnification spec.
- * @param transformMatrix The transform matrix of the window doesn't consider the
- * magnifying effect.
- */
- @GuardedBy("mLock")
- private void generateMagnificationSpecInverseMatrix(InputWindowHandle inputWindowHandle,
- @NonNull MagnificationSpec currentMagnificationSpec,
- @NonNull MagnificationSpec previousMagnificationSpec, Matrix transformMatrix) {
-
- final float[] identityMatrixFloatsForCurrentSpec = mTempFloat1;
- computeIdentityMatrix(inputWindowHandle, currentMagnificationSpec,
- transformMatrix, identityMatrixFloatsForCurrentSpec);
- final float[] identityMatrixFloatsForPreviousSpec = mTempFloat2;
- computeIdentityMatrix(inputWindowHandle, previousMagnificationSpec,
- transformMatrix, identityMatrixFloatsForPreviousSpec);
-
- Matrix inverseMatrixForMagnificationSpec = new Matrix();
- if (selectProperMagnificationSpecByComparingIdentityDegree(
- identityMatrixFloatsForCurrentSpec, identityMatrixFloatsForPreviousSpec)) {
- generateInverseMatrix(currentMagnificationSpec,
- inverseMatrixForMagnificationSpec);
-
- // Choosing the current spec means the previous spec is out of date,
- // so removing it. And if the current spec is no magnifying, meaning
- // the magnifying is done so removing the inverse matrix of this display.
- mPreviousMagnificationSpec.remove(inputWindowHandle.displayId);
- if (currentMagnificationSpec.isNop()) {
- mCurrentMagnificationSpec.remove(inputWindowHandle.displayId);
- mMagnificationSpecInverseMatrix.remove(inputWindowHandle.displayId);
- return;
- }
- } else {
- generateInverseMatrix(previousMagnificationSpec,
- inverseMatrixForMagnificationSpec);
- }
-
- mMagnificationSpecInverseMatrix.put(inputWindowHandle.displayId,
- inverseMatrixForMagnificationSpec);
- }
-
- /**
- * Computes the identity matrix for generating the
- * inverse matrix based on below formula under window is at the stable state:
- * inputWindowHandle#transform * MagnificationSpecMatrix * WindowState#transform
- * = IdentityMatrix
- */
- @GuardedBy("mLock")
- private void computeIdentityMatrix(InputWindowHandle inputWindowHandle,
- @NonNull MagnificationSpec magnificationSpec,
- Matrix transformMatrix, float[] magnifyMatrixFloats) {
- final Matrix specMatrix = mTempMatrix1;
- transformMagnificationSpecToMatrix(magnificationSpec, specMatrix);
-
- final Matrix resultMatrix = new Matrix(inputWindowHandle.transform);
- resultMatrix.preConcat(specMatrix);
- resultMatrix.preConcat(transformMatrix);
-
- resultMatrix.getValues(magnifyMatrixFloats);
- }
-
- /**
- * @return true if selecting the magnification spec one, otherwise selecting the
- * magnification spec two.
- */
- @GuardedBy("mLock")
- private boolean selectProperMagnificationSpecByComparingIdentityDegree(
- float[] magnifyMatrixFloatsForSpecOne,
- float[] magnifyMatrixFloatsForSpecTwo) {
- final float[] IdentityMatrixValues = mTempFloat3;
- Matrix.IDENTITY_MATRIX.getValues(IdentityMatrixValues);
-
- final float scaleDiffForSpecOne = Math.abs(IdentityMatrixValues[Matrix.MSCALE_X]
- - magnifyMatrixFloatsForSpecOne[Matrix.MSCALE_X]);
- final float scaleDiffForSpecTwo = Math.abs(IdentityMatrixValues[Matrix.MSCALE_X]
- - magnifyMatrixFloatsForSpecTwo[Matrix.MSCALE_X]);
- final float offsetXDiffForSpecOne = Math.abs(IdentityMatrixValues[Matrix.MTRANS_X]
- - magnifyMatrixFloatsForSpecOne[Matrix.MTRANS_X]);
- final float offsetXDiffForSpecTwo = Math.abs(IdentityMatrixValues[Matrix.MTRANS_X]
- - magnifyMatrixFloatsForSpecTwo[Matrix.MTRANS_X]);
- final float offsetYDiffForSpecOne = Math.abs(IdentityMatrixValues[Matrix.MTRANS_Y]
- - magnifyMatrixFloatsForSpecOne[Matrix.MTRANS_Y]);
- final float offsetYDiffForSpecTwo = Math.abs(IdentityMatrixValues[Matrix.MTRANS_Y]
- - magnifyMatrixFloatsForSpecTwo[Matrix.MTRANS_Y]);
- final float offsetDiffForSpecOne = offsetXDiffForSpecOne
- + offsetYDiffForSpecOne;
- final float offsetDiffForSpecTwo = offsetXDiffForSpecTwo
- + offsetYDiffForSpecTwo;
-
- return Float.compare(scaleDiffForSpecTwo, scaleDiffForSpecOne) > 0
- || (Float.compare(scaleDiffForSpecTwo, scaleDiffForSpecOne) == 0
- && Float.compare(offsetDiffForSpecTwo, offsetDiffForSpecOne) > 0);
- }
-
- @GuardedBy("mLock")
- private static void generateInverseMatrix(MagnificationSpec spec, Matrix outMatrix) {
- outMatrix.reset();
+ sTempFloats[Matrix.MSCALE_X] = spec.scale;
+ sTempFloats[Matrix.MSKEW_Y] = 0;
+ sTempFloats[Matrix.MSKEW_X] = 0;
+ sTempFloats[Matrix.MSCALE_Y] = spec.scale;
+ sTempFloats[Matrix.MTRANS_X] = spec.offsetX;
+ sTempFloats[Matrix.MTRANS_Y] = spec.offsetY;
+ sTempFloats[Matrix.MPERSP_0] = 0;
+ sTempFloats[Matrix.MPERSP_1] = 0;
+ sTempFloats[Matrix.MPERSP_2] = 1;
final Matrix tempMatrix = new Matrix();
- transformMagnificationSpecToMatrix(spec, tempMatrix);
+ tempMatrix.setValues(sTempFloats);
- final boolean result = tempMatrix.invert(outMatrix);
+ final Matrix inverseMatrix = new Matrix();
+ final boolean result = tempMatrix.invert(inverseMatrix);
+
if (!result) {
Slog.e(TAG, "Can't inverse the magnification spec matrix with the "
- + "magnification spec = " + spec);
- outMatrix.reset();
+ + "magnification spec = " + spec + " on the displayId = " + displayId);
+ return;
}
- }
-
- @GuardedBy("mLock")
- private static void transformMagnificationSpecToMatrix(MagnificationSpec spec,
- Matrix outMatrix) {
- outMatrix.reset();
- outMatrix.postScale(spec.scale, spec.scale);
- outMatrix.postTranslate(spec.offsetX, spec.offsetY);
+ mMagnificationSpecInverseMatrix.set(displayId, inverseMatrix);
}
private void notifyWindowsChanged(@NonNull List<Integer> displayIdsForWindowsChanged) {
@@ -542,9 +310,6 @@
mMagnificationSpecInverseMatrix.clear();
mVisibleWindows.clear();
mDisplayInfos.clear();
- mCurrentMagnificationSpec.clear();
- mPreviousMagnificationSpec.clear();
- mWindowsTransformMatrixMap.clear();
mWindowsNotificationEnabled = false;
mHandler.removeCallbacksAndMessages(null);
}
diff --git a/services/core/java/com/android/server/wm/ActivityInterceptorCallback.java b/services/core/java/com/android/server/wm/ActivityInterceptorCallback.java
index 4df2e17..06c58ba 100644
--- a/services/core/java/com/android/server/wm/ActivityInterceptorCallback.java
+++ b/services/core/java/com/android/server/wm/ActivityInterceptorCallback.java
@@ -43,9 +43,13 @@
public abstract @Nullable ActivityInterceptResult intercept(ActivityInterceptorInfo info);
/**
- * Called when an activity is successfully launched.
+ * Called when an activity is successfully launched. The intent included in the
+ * ActivityInterceptorInfo may have changed from the one sent in
+ * {@link #intercept(ActivityInterceptorInfo)}, due to the return from
+ * {@link #intercept(ActivityInterceptorInfo)}.
*/
- public void onActivityLaunched(TaskInfo taskInfo, ActivityInfo activityInfo) {
+ public void onActivityLaunched(TaskInfo taskInfo, ActivityInfo activityInfo,
+ ActivityInterceptorInfo info) {
}
/**
diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java
index 26815b4..9c910eb 100644
--- a/services/core/java/com/android/server/wm/ActivityRecord.java
+++ b/services/core/java/com/android/server/wm/ActivityRecord.java
@@ -44,6 +44,7 @@
import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
import static android.app.WindowConfiguration.WINDOWING_MODE_MULTI_WINDOW;
import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;
+import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED;
import static android.app.WindowConfiguration.activityTypeToString;
import static android.app.WindowConfiguration.isSplitScreenWindowingMode;
import static android.app.admin.DevicePolicyResources.Drawables.Source.PROFILE_SWITCH_ANIMATION;
@@ -3247,7 +3248,8 @@
// the best capture timing (e.g. IME window capture),
// No need additional task capture while task is controlled by RecentsAnimation.
if (mAtmService.mWindowManager.mTaskSnapshotController != null
- && !task.isAnimatingByRecents()) {
+ && !(task.isAnimatingByRecents()
+ || mTransitionController.inRecentsTransition(task))) {
final ArraySet<Task> tasks = Sets.newArraySet(task);
mAtmService.mWindowManager.mTaskSnapshotController.snapshotTasks(tasks);
mAtmService.mWindowManager.mTaskSnapshotController
@@ -8211,6 +8213,20 @@
@Override
public void onConfigurationChanged(Configuration newParentConfig) {
+ // We want to collect the ActivityRecord if the windowing mode is changed, so that it will
+ // dispatch app transition finished event correctly at the end.
+ // Check #isVisible() because we don't want to animate for activity that stays invisible.
+ // Activity with #isVisibleRequested() changed should be collected when that is requested.
+ if (mTransitionController.isShellTransitionsEnabled() && isVisible()
+ && isVisibleRequested()) {
+ final int projectedWindowingMode =
+ getRequestedOverrideWindowingMode() == WINDOWING_MODE_UNDEFINED
+ ? newParentConfig.windowConfiguration.getWindowingMode()
+ : getRequestedOverrideWindowingMode();
+ if (getWindowingMode() != projectedWindowingMode) {
+ mTransitionController.collect(this);
+ }
+ }
if (mCompatDisplayInsets != null) {
Configuration overrideConfig = getRequestedOverrideConfiguration();
// Adapt to changes in orientation locking. The app is still non-resizable, but
diff --git a/services/core/java/com/android/server/wm/ActivityRecordInputSink.java b/services/core/java/com/android/server/wm/ActivityRecordInputSink.java
index 316bf20..19d5449 100644
--- a/services/core/java/com/android/server/wm/ActivityRecordInputSink.java
+++ b/services/core/java/com/android/server/wm/ActivityRecordInputSink.java
@@ -16,10 +16,6 @@
package com.android.server.wm;
-import static com.android.server.wm.SurfaceAnimator.ANIMATION_TYPE_APP_TRANSITION;
-import static com.android.server.wm.WindowContainer.AnimationFlags.PARENTS;
-import static com.android.server.wm.WindowContainer.AnimationFlags.TRANSITION;
-
import android.app.compat.CompatChanges;
import android.compat.annotation.ChangeId;
import android.os.IBinder;
@@ -101,8 +97,7 @@
mToken = inputChannel.getToken();
mInputEventReceiver = createInputEventReceiver(inputChannel);
}
- if (mDisabled || !mIsCompatEnabled || mActivityRecord.isAnimating(TRANSITION | PARENTS,
- ANIMATION_TYPE_APP_TRANSITION)) {
+ if (mDisabled || !mIsCompatEnabled || mActivityRecord.isInTransition()) {
// TODO(b/208662670): Investigate if we can have feature active during animations.
mInputWindowHandleWrapper.setToken(null);
} else {
diff --git a/services/core/java/com/android/server/wm/ActivityStartInterceptor.java b/services/core/java/com/android/server/wm/ActivityStartInterceptor.java
index 658a17b..c5fcd12 100644
--- a/services/core/java/com/android/server/wm/ActivityStartInterceptor.java
+++ b/services/core/java/com/android/server/wm/ActivityStartInterceptor.java
@@ -188,10 +188,7 @@
final SparseArray<ActivityInterceptorCallback> callbacks =
mService.getActivityInterceptorCallbacks();
final ActivityInterceptorCallback.ActivityInterceptorInfo interceptorInfo =
- new ActivityInterceptorCallback.ActivityInterceptorInfo(mRealCallingUid,
- mRealCallingPid, mUserId, mCallingPackage, mCallingFeatureId, mIntent,
- mRInfo, mAInfo, mResolvedType, mCallingPid, mCallingUid,
- mActivityOptions);
+ getInterceptorInfo();
for (int i = 0; i < callbacks.size(); i++) {
final ActivityInterceptorCallback callback = callbacks.valueAt(i);
@@ -412,9 +409,17 @@
void onActivityLaunched(TaskInfo taskInfo, ActivityInfo activityInfo) {
final SparseArray<ActivityInterceptorCallback> callbacks =
mService.getActivityInterceptorCallbacks();
+ ActivityInterceptorCallback.ActivityInterceptorInfo info = getInterceptorInfo();
for (int i = 0; i < callbacks.size(); i++) {
final ActivityInterceptorCallback callback = callbacks.valueAt(i);
- callback.onActivityLaunched(taskInfo, activityInfo);
+ callback.onActivityLaunched(taskInfo, activityInfo, info);
}
}
+
+ private ActivityInterceptorCallback.ActivityInterceptorInfo getInterceptorInfo() {
+ return new ActivityInterceptorCallback.ActivityInterceptorInfo(mRealCallingUid,
+ mRealCallingPid, mUserId, mCallingPackage, mCallingFeatureId, mIntent,
+ mRInfo, mAInfo, mResolvedType, mCallingPid, mCallingUid,
+ mActivityOptions);
+ }
}
diff --git a/services/core/java/com/android/server/wm/AsyncRotationController.java b/services/core/java/com/android/server/wm/AsyncRotationController.java
index 5c13e81..9e889ad 100644
--- a/services/core/java/com/android/server/wm/AsyncRotationController.java
+++ b/services/core/java/com/android/server/wm/AsyncRotationController.java
@@ -94,6 +94,9 @@
/** Whether the start transaction of the transition is committed (by shell). */
private boolean mIsStartTransactionCommitted;
+ /** Whether the target windows have been requested to sync their draw transactions. */
+ private boolean mIsSyncDrawRequested;
+
private SeamlessRotator mRotator;
private final int mOriginalRotation;
@@ -139,22 +142,10 @@
displayContent.forAllWindows(this, true /* traverseTopToBottom */);
// Legacy animation doesn't need to wait for the start transaction.
- mIsStartTransactionCommitted = mTransitionOp == OP_LEGACY;
- if (mIsStartTransactionCommitted) return;
- // The transition sync group may be finished earlier because it doesn't wait for these
- // target windows. But the windows still need to use sync transaction to keep the appearance
- // in previous rotation, so request a no-op sync to keep the state.
- for (int i = mTargetWindowTokens.size() - 1; i >= 0; i--) {
- if (mHasScreenRotationAnimation
- && mTargetWindowTokens.valueAt(i).mAction == Operation.ACTION_FADE) {
- // The windows are hidden (leash is alpha 0) before finishing drawing so it is
- // unnecessary to request sync.
- continue;
- }
- final WindowToken token = mTargetWindowTokens.keyAt(i);
- for (int j = token.getChildCount() - 1; j >= 0; j--) {
- token.getChildAt(j).applyWithNextDraw(t -> {});
- }
+ if (mTransitionOp == OP_LEGACY) {
+ mIsStartTransactionCommitted = true;
+ } else if (displayContent.mTransitionController.useShellTransitionsRotation()) {
+ keepAppearanceInPreviousRotation();
}
}
@@ -194,6 +185,30 @@
mTargetWindowTokens.put(w.mToken, new Operation(action));
}
+ /**
+ * Enables {@link #handleFinishDrawing(WindowState, SurfaceControl.Transaction)} to capture the
+ * draw transactions of the target windows if needed.
+ */
+ void keepAppearanceInPreviousRotation() {
+ // The transition sync group may be finished earlier because it doesn't wait for these
+ // target windows. But the windows still need to use sync transaction to keep the appearance
+ // in previous rotation, so request a no-op sync to keep the state.
+ for (int i = mTargetWindowTokens.size() - 1; i >= 0; i--) {
+ if (mHasScreenRotationAnimation
+ && mTargetWindowTokens.valueAt(i).mAction == Operation.ACTION_FADE) {
+ // The windows are hidden (leash is alpha 0) before finishing drawing so it is
+ // unnecessary to request sync.
+ continue;
+ }
+ final WindowToken token = mTargetWindowTokens.keyAt(i);
+ for (int j = token.getChildCount() - 1; j >= 0; j--) {
+ token.getChildAt(j).applyWithNextDraw(t -> {});
+ }
+ }
+ mIsSyncDrawRequested = true;
+ if (DEBUG) Slog.d(TAG, "Requested to sync draw transaction");
+ }
+
/** Lets the window fit in new rotation naturally. */
private void finishOp(WindowToken windowToken) {
final Operation op = mTargetWindowTokens.remove(windowToken);
@@ -433,7 +448,7 @@
*/
boolean handleFinishDrawing(WindowState w, SurfaceControl.Transaction postDrawTransaction) {
if (mTransitionOp == OP_LEGACY || postDrawTransaction == null
- || !w.mTransitionController.inTransition()) {
+ || !mIsSyncDrawRequested || !w.mTransitionController.inTransition()) {
return false;
}
final Operation op = mTargetWindowTokens.get(w.mToken);
diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java
index 195d425..1c0687a 100644
--- a/services/core/java/com/android/server/wm/DisplayContent.java
+++ b/services/core/java/com/android/server/wm/DisplayContent.java
@@ -1735,19 +1735,19 @@
}
void setFixedRotationLaunchingAppUnchecked(@Nullable ActivityRecord r, int rotation) {
- final boolean useAsyncRotation = !mTransitionController.isShellTransitionsEnabled();
if (mFixedRotationLaunchingApp == null && r != null) {
- mWmService.mDisplayNotificationController.dispatchFixedRotationStarted(this,
- rotation);
- if (useAsyncRotation) {
- startAsyncRotation(
- // Delay the hide animation to avoid blinking by clicking navigation bar
- // that may toggle fixed rotation in a short time.
- r == mFixedRotationTransitionListener.mAnimatingRecents);
- }
+ mWmService.mDisplayNotificationController.dispatchFixedRotationStarted(this, rotation);
+ // Delay the hide animation to avoid blinking by clicking navigation bar that may
+ // toggle fixed rotation in a short time.
+ final boolean shouldDebounce = r == mFixedRotationTransitionListener.mAnimatingRecents
+ || mTransitionController.isTransientLaunch(r);
+ startAsyncRotation(shouldDebounce);
} else if (mFixedRotationLaunchingApp != null && r == null) {
mWmService.mDisplayNotificationController.dispatchFixedRotationFinished(this);
- if (useAsyncRotation) finishAsyncRotationIfPossible();
+ // Keep async rotation controller if the next transition of display is requested.
+ if (!mTransitionController.isCollecting(this)) {
+ finishAsyncRotationIfPossible();
+ }
}
mFixedRotationLaunchingApp = r;
}
@@ -1805,7 +1805,6 @@
}
// Update directly because the app which will change the orientation of display is ready.
if (mDisplayRotation.updateOrientation(getOrientation(), false /* forceUpdate */)) {
- mTransitionController.setSeamlessRotation(this);
sendNewConfiguration();
return;
}
@@ -3234,7 +3233,15 @@
this, this, null /* remoteTransition */, displayChange);
if (t != null) {
mAtmService.startLaunchPowerMode(POWER_MODE_REASON_CHANGE_DISPLAY);
- if (isRotationChanging()) {
+ if (mFixedRotationLaunchingApp != null) {
+ // A fixed-rotation transition is done, then continue to start a seamless display
+ // transition. And be fore the start transaction is applied, the non-app windows
+ // need to keep in previous rotation to avoid showing inconsistent content.
+ t.setSeamlessRotation(this);
+ if (mAsyncRotationController != null) {
+ mAsyncRotationController.keepAppearanceInPreviousRotation();
+ }
+ } else if (isRotationChanging()) {
mWmService.mLatencyTracker.onActionStart(ACTION_ROTATE_SCREEN);
controller.mTransitionMetricsReporter.associate(t,
startTime -> mWmService.mLatencyTracker.onActionEnd(ACTION_ROTATE_SCREEN));
@@ -6361,13 +6368,28 @@
}
/**
- * Return {@code true} if there is an ongoing animation to the "Recents" activity and this
- * activity as a fixed orientation so shouldn't be rotated.
+ * Returns the fixed orientation requested by a transient launch (e.g. recents animation).
+ * If it doesn't return SCREEN_ORIENTATION_UNSET, the rotation change should be deferred.
*/
- boolean isTopFixedOrientationRecentsAnimating() {
- return mAnimatingRecents != null
- && mAnimatingRecents.getRequestedConfigurationOrientation(true /* forDisplay */)
- != ORIENTATION_UNDEFINED && !hasTopFixedRotationLaunchingApp();
+ @ActivityInfo.ScreenOrientation int getTransientFixedOrientation() {
+ ActivityRecord source = null;
+ if (mTransitionController.isShellTransitionsEnabled()) {
+ final ActivityRecord r = mFixedRotationLaunchingApp;
+ if (r != null && mTransitionController.isTransientLaunch(r)) {
+ source = r;
+ }
+ } else if (mAnimatingRecents != null && !hasTopFixedRotationLaunchingApp()) {
+ source = mAnimatingRecents;
+ }
+ if (source == null || source.getRequestedConfigurationOrientation(
+ true /* forDisplay */) == ORIENTATION_UNDEFINED) {
+ return SCREEN_ORIENTATION_UNSET;
+ }
+ if (!mWmService.mPolicy.okToAnimate(false /* ignoreScreenOn */)) {
+ // If screen is off or the device is going to sleep, then still allow to update.
+ return SCREEN_ORIENTATION_UNSET;
+ }
+ return source.mOrientation;
}
@Override
diff --git a/services/core/java/com/android/server/wm/DisplayRotation.java b/services/core/java/com/android/server/wm/DisplayRotation.java
index 6438d79..f116fff 100644
--- a/services/core/java/com/android/server/wm/DisplayRotation.java
+++ b/services/core/java/com/android/server/wm/DisplayRotation.java
@@ -419,11 +419,8 @@
* THE SCREEN.
*/
boolean updateRotationUnchecked(boolean forceUpdate) {
- final boolean useShellTransitions =
- mDisplayContent.mTransitionController.isShellTransitionsEnabled();
-
final int displayId = mDisplayContent.getDisplayId();
- if (!forceUpdate && !useShellTransitions) {
+ if (!forceUpdate) {
if (mDeferredRotationPauseCount > 0) {
// Rotation updates have been paused temporarily. Defer the update until updates
// have been resumed.
@@ -449,17 +446,16 @@
return false;
}
- final RecentsAnimationController recentsAnimController =
- mService.getRecentsAnimationController();
- if (recentsAnimController != null && mDisplayContent.mFixedRotationTransitionListener
- .isTopFixedOrientationRecentsAnimating()
- // If screen is off or the device is going to sleep, then still allow to update.
- && mService.mPolicy.okToAnimate(false /* ignoreScreenOn */)) {
+ final int transientFixedOrientation =
+ mDisplayContent.mFixedRotationTransitionListener.getTransientFixedOrientation();
+ if (transientFixedOrientation != SCREEN_ORIENTATION_UNSET) {
+ // Makes sure that after the transition is finished, updateOrientation() can see
+ // the difference from the latest orientation source.
+ mLastOrientation = transientFixedOrientation;
// During the recents animation, the closing app might still be considered on top.
// In order to ignore its requested orientation to avoid a sensor led rotation (e.g
// user rotating the device while the recents animation is running), we ignore
// rotation update while the animation is running.
- recentsAnimController.setCheckRotationAfterCleanup();
return false;
}
}
@@ -513,7 +509,7 @@
mDisplayContent.setLayoutNeeded();
- if (useShellTransitions) {
+ if (mDisplayContent.mTransitionController.isShellTransitionsEnabled()) {
final boolean wasCollecting = mDisplayContent.mTransitionController.isCollecting();
final TransitionRequestInfo.DisplayChange change = wasCollecting ? null
: new TransitionRequestInfo.DisplayChange(mDisplayContent.getDisplayId(),
diff --git a/services/core/java/com/android/server/wm/RecentsAnimationController.java b/services/core/java/com/android/server/wm/RecentsAnimationController.java
index 30906e5..93714e8 100644
--- a/services/core/java/com/android/server/wm/RecentsAnimationController.java
+++ b/services/core/java/com/android/server/wm/RecentsAnimationController.java
@@ -122,7 +122,6 @@
private final int mDisplayId;
private boolean mWillFinishToHome = false;
private final Runnable mFailsafeRunnable = this::onFailsafe;
- private Runnable mCheckRotationAfterCleanup;
// The recents component app token that is shown behind the visibile tasks
private ActivityRecord mTargetActivityRecord;
@@ -920,24 +919,6 @@
}
/**
- * If the display rotation change is ignored while recents animation is running, make sure that
- * the pending rotation change will be applied after the animation finishes.
- */
- void setCheckRotationAfterCleanup() {
- if (mCheckRotationAfterCleanup != null) return;
- mCheckRotationAfterCleanup = () -> {
- synchronized (mService.mGlobalLock) {
- if (mDisplayContent.getDisplayRotation()
- .updateRotationAndSendNewConfigIfChanged()) {
- if (mTargetActivityRecord != null) {
- mTargetActivityRecord.finishFixedRotationTransform();
- }
- }
- }
- };
- }
-
- /**
* @return Whether we should defer the cancel from a root task order change until the next app
* transition.
*/
@@ -1037,10 +1018,6 @@
if (mStatusBar != null) {
mStatusBar.onRecentsAnimationStateChanged(false /* running */);
}
- if (mCheckRotationAfterCleanup != null) {
- mService.mH.post(mCheckRotationAfterCleanup);
- mCheckRotationAfterCleanup = null;
- }
}
void scheduleFailsafe() {
diff --git a/services/core/java/com/android/server/wm/Task.java b/services/core/java/com/android/server/wm/Task.java
index cc03c60..f3933c5 100644
--- a/services/core/java/com/android/server/wm/Task.java
+++ b/services/core/java/com/android/server/wm/Task.java
@@ -3292,7 +3292,7 @@
// We intend to let organizer manage task visibility but it doesn't
// have enough information until we finish shell transitions.
// In the mean time we do an easy fix here.
- final boolean show = isVisible() || isAnimating(TRANSITION | PARENTS);
+ final boolean show = isVisible() || isAnimating(TRANSITION | PARENTS | CHILDREN);
if (mSurfaceControl != null) {
if (show != mLastSurfaceShowing) {
getSyncTransaction().setVisibility(mSurfaceControl, show);
diff --git a/services/core/java/com/android/server/wm/TaskOrganizerController.java b/services/core/java/com/android/server/wm/TaskOrganizerController.java
index 037d582..331f124 100644
--- a/services/core/java/com/android/server/wm/TaskOrganizerController.java
+++ b/services/core/java/com/android/server/wm/TaskOrganizerController.java
@@ -729,6 +729,16 @@
// Skip if task still not appeared.
return;
}
+ if (force && mPendingTaskEvents.isEmpty()) {
+ // There are task-info changed events do not result in
+ // - RootWindowContainer#performSurfacePlacementNoTrace OR
+ // - WindowAnimator#animate
+ // For instance, when an app requesting aspect ratio change when in PiP mode.
+ // To solve this, we directly dispatch the pending event if there are no events queued (
+ // otherwise, all pending events should be dispatched on next drawn).
+ dispatchTaskInfoChanged(task, true /* force */);
+ return;
+ }
// Defer task info reporting while layout is deferred. This is because layout defer
// blocks tend to do lots of re-ordering which can mess up animations in receivers.
diff --git a/services/core/java/com/android/server/wm/TaskSnapshotController.java b/services/core/java/com/android/server/wm/TaskSnapshotController.java
index 6a23eb5..cde9927 100644
--- a/services/core/java/com/android/server/wm/TaskSnapshotController.java
+++ b/services/core/java/com/android/server/wm/TaskSnapshotController.java
@@ -534,7 +534,7 @@
// Since RecentsAnimation will handle task snapshot while switching apps with the
// best capture timing (e.g. IME window capture),
// No need additional task capture while task is controlled by RecentsAnimation.
- if (task.isAnimatingByRecents()) {
+ if (isAnimatingByRecents(task)) {
mSkipClosingAppSnapshotTasks.add(task);
}
// If the task of the app is not visible anymore, it means no other app in that task
@@ -686,7 +686,7 @@
// Since RecentsAnimation will handle task snapshot while switching apps with the best
// capture timing (e.g. IME window capture), No need additional task capture while task
// is controlled by RecentsAnimation.
- if (task.isVisible() && !task.isAnimatingByRecents()) {
+ if (task.isVisible() && !isAnimatingByRecents(task)) {
mTmpTasks.add(task);
}
});
@@ -717,6 +717,11 @@
frame, Type.systemBars(), false /* ignoreVisibility */).toRect();
}
+ private boolean isAnimatingByRecents(@NonNull Task task) {
+ return task.isAnimatingByRecents()
+ || mService.mAtmService.getTransitionController().inRecentsTransition(task);
+ }
+
void dump(PrintWriter pw, String prefix) {
pw.println(prefix + "mHighResTaskSnapshotScale=" + mHighResTaskSnapshotScale);
pw.println(prefix + "mTaskSnapshotEnabled=" + mTaskSnapshotEnabled);
diff --git a/services/core/java/com/android/server/wm/Transition.java b/services/core/java/com/android/server/wm/Transition.java
index 0f5828c..29d1742 100644
--- a/services/core/java/com/android/server/wm/Transition.java
+++ b/services/core/java/com/android/server/wm/Transition.java
@@ -80,9 +80,12 @@
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.graphics.ColorUtils;
+import com.android.internal.inputmethod.SoftInputShowHideReason;
import com.android.internal.protolog.ProtoLogGroup;
import com.android.internal.protolog.common.ProtoLog;
import com.android.internal.util.function.pooled.PooledLambda;
+import com.android.server.LocalServices;
+import com.android.server.inputmethod.InputMethodManagerInternal;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -548,18 +551,28 @@
for (int i = 0; i < mTargetDisplays.size(); ++i) {
final DisplayContent dc = mTargetDisplays.get(i);
final AsyncRotationController asyncRotationController = dc.getAsyncRotationController();
- if (asyncRotationController != null) {
+ if (asyncRotationController != null && mTargets.contains(dc)) {
asyncRotationController.onTransitionFinished();
}
if (mTransientLaunches != null) {
+ InsetsControlTarget prevImeTarget = dc.getImeTarget(
+ DisplayContent.IME_TARGET_CONTROL);
+ InsetsControlTarget newImeTarget = null;
// Transient-launch activities cannot be IME target (WindowState#canBeImeTarget),
// so re-compute in case the IME target is changed after transition.
for (int t = 0; t < mTransientLaunches.size(); ++t) {
if (mTransientLaunches.keyAt(t).getDisplayContent() == dc) {
- dc.computeImeTarget(true /* updateImeTarget */);
+ newImeTarget = dc.computeImeTarget(true /* updateImeTarget */);
break;
}
}
+ if (mRecentsDisplayId != INVALID_DISPLAY && prevImeTarget == newImeTarget) {
+ // Restore IME icon only when moving the original app task to front from
+ // recents, in case IME icon may missing if the moving task has already been
+ // the current focused task.
+ InputMethodManagerInternal.get().updateImeWindowStatus(
+ false /* disableImeIcon */);
+ }
}
dc.handleCompleteDeferredRemoval();
}
@@ -696,7 +709,7 @@
// This is non-null only if display has changes. It handles the visible windows that don't
// need to be participated in the transition.
final AsyncRotationController controller = dc.getAsyncRotationController();
- if (controller != null) {
+ if (controller != null && mTargets.contains(dc)) {
controller.setupStartTransaction(transaction);
}
mStartTransaction = transaction;
@@ -781,6 +794,26 @@
}
}
+ // Hiding IME/IME icon when starting quick-step with resents animation.
+ if (!mTargetDisplays.get(mRecentsDisplayId).isImeAttachedToApp()) {
+ // Hiding IME if IME window is not attached to app.
+ // Since some windowing mode is not proper to snapshot Task with IME window
+ // while the app transitioning to the next task (e.g. split-screen mode)
+ final InputMethodManagerInternal inputMethodManagerInternal =
+ LocalServices.getService(InputMethodManagerInternal.class);
+ if (inputMethodManagerInternal != null) {
+ inputMethodManagerInternal.hideCurrentInputMethod(
+ SoftInputShowHideReason.HIDE_RECENTS_ANIMATION);
+ }
+ } else {
+ // Disable IME icon explicitly when IME attached to the app in case
+ // IME icon might flickering while swiping to the next app task still
+ // in animating before the next app window focused, or IME icon
+ // persists on the bottom when swiping the task to recents.
+ InputMethodManagerInternal.get().updateImeWindowStatus(
+ true /* disableImeIcon */);
+ }
+
// The rest of this function handles nav-bar reparenting
if (!dc.getDisplayPolicy().shouldAttachNavBarToAppDuringTransition()
diff --git a/services/core/java/com/android/server/wm/TransitionController.java b/services/core/java/com/android/server/wm/TransitionController.java
index b0532c2..0436233 100644
--- a/services/core/java/com/android/server/wm/TransitionController.java
+++ b/services/core/java/com/android/server/wm/TransitionController.java
@@ -16,7 +16,6 @@
package com.android.server.wm;
-import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME;
import static android.view.WindowManager.TRANSIT_CHANGE;
import static android.view.WindowManager.TRANSIT_CLOSE;
import static android.view.WindowManager.TRANSIT_FLAG_IS_RECENTS;
@@ -246,7 +245,7 @@
/** @return {@code true} if wc is in a participant subtree */
boolean inTransition(@NonNull WindowContainer wc) {
- if (isCollecting(wc)) return true;
+ if (isCollecting(wc)) return true;
for (int i = mPlayingTransitions.size() - 1; i >= 0; --i) {
for (WindowContainer p = wc; p != null; p = p.getParent()) {
if (mPlayingTransitions.get(i).mParticipants.contains(p)) {
@@ -257,6 +256,28 @@
return false;
}
+ boolean inRecentsTransition(@NonNull WindowContainer wc) {
+ for (WindowContainer p = wc; p != null; p = p.getParent()) {
+ // TODO(b/221417431): replace this with deterministic snapshots
+ if (mCollectingTransition == null) break;
+ if ((mCollectingTransition.getFlags() & TRANSIT_FLAG_IS_RECENTS) != 0
+ && mCollectingTransition.mParticipants.contains(wc)) {
+ return true;
+ }
+ }
+
+ for (int i = mPlayingTransitions.size() - 1; i >= 0; --i) {
+ for (WindowContainer p = wc; p != null; p = p.getParent()) {
+ // TODO(b/221417431): replace this with deterministic snapshots
+ if ((mPlayingTransitions.get(i).getFlags() & TRANSIT_FLAG_IS_RECENTS) != 0
+ && mPlayingTransitions.get(i).mParticipants.contains(p)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
/** @return {@code true} if wc is in a participant subtree */
boolean isTransitionOnDisplay(@NonNull DisplayContent dc) {
if (mCollectingTransition != null && mCollectingTransition.isOnDisplay(dc)) {
@@ -514,16 +535,16 @@
// TODO(b/188669821): Remove once legacy recents behavior is moved to shell.
// Also interpret HOME transient launch as recents
- if (activity.getActivityType() == ACTIVITY_TYPE_HOME) {
+ if (activity.isActivityTypeHomeOrRecents()) {
mCollectingTransition.addFlag(TRANSIT_FLAG_IS_RECENTS);
+ // When starting recents animation, we assume the recents activity is behind the app
+ // task and should not affect system bar appearance,
+ // until WMS#setRecentsAppBehindSystemBars be called from launcher when passing
+ // the gesture threshold.
+ activity.getTask().setCanAffectSystemUiFlags(false);
}
}
- void setSeamlessRotation(@NonNull WindowContainer wc) {
- if (mCollectingTransition == null) return;
- mCollectingTransition.setSeamlessRotation(wc);
- }
-
void legacyDetachNavigationBarFromApp(@NonNull IBinder token) {
final Transition transition = Transition.fromBinder(token);
if (transition == null || !mPlayingTransitions.contains(transition)) {
diff --git a/services/core/java/com/android/server/wm/WindowContainer.java b/services/core/java/com/android/server/wm/WindowContainer.java
index d306082..56014ad 100644
--- a/services/core/java/com/android/server/wm/WindowContainer.java
+++ b/services/core/java/com/android/server/wm/WindowContainer.java
@@ -47,6 +47,7 @@
import static com.android.server.wm.IdentifierProto.USER_ID;
import static com.android.server.wm.SurfaceAnimator.ANIMATION_TYPE_ALL;
import static com.android.server.wm.SurfaceAnimator.ANIMATION_TYPE_APP_TRANSITION;
+import static com.android.server.wm.SurfaceAnimator.ANIMATION_TYPE_RECENTS;
import static com.android.server.wm.WindowContainer.AnimationFlags.CHILDREN;
import static com.android.server.wm.WindowContainer.AnimationFlags.PARENTS;
import static com.android.server.wm.WindowContainer.AnimationFlags.TRANSITION;
@@ -1173,6 +1174,27 @@
return mTransitionController.inTransition(this);
}
+ boolean inAppOrRecentsTransition() {
+ if (!mTransitionController.isShellTransitionsEnabled()) {
+ return isAnimating(PARENTS | TRANSITION,
+ ANIMATION_TYPE_APP_TRANSITION | ANIMATION_TYPE_RECENTS);
+ }
+ for (WindowContainer p = this; p != null; p = p.getParent()) {
+ if (mTransitionController.isCollecting(p)) {
+ return true;
+ }
+ }
+ if (inTransition() || mTransitionController.inRecentsTransition(this)) return true;
+
+ for (int i = mChildren.size() - 1; i >= 0; --i) {
+ WindowContainer child = mChildren.get(i);
+ if (child.inAppOrRecentsTransition()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
void sendAppVisibilityToClients() {
for (int i = mChildren.size() - 1; i >= 0; --i) {
final WindowContainer wc = mChildren.get(i);
diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java
index 6445d1e..5eb8187 100644
--- a/services/core/java/com/android/server/wm/WindowManagerService.java
+++ b/services/core/java/com/android/server/wm/WindowManagerService.java
@@ -25,6 +25,7 @@
import static android.Manifest.permission.READ_FRAME_BUFFER;
import static android.Manifest.permission.REGISTER_WINDOW_MANAGER_LISTENERS;
import static android.Manifest.permission.RESTRICTED_VR_ACCESS;
+import static android.Manifest.permission.START_TASKS_FROM_RECENTS;
import static android.Manifest.permission.WRITE_SECURE_SETTINGS;
import static android.app.ActivityManagerInternal.ALLOW_FULL_ONLY;
import static android.app.ActivityManagerInternal.ALLOW_NON_FULL;
@@ -3034,7 +3035,7 @@
@Override
public void onKeyguardShowingAndNotOccludedChanged() {
mH.sendEmptyMessage(H.RECOMPUTE_FOCUS);
- dispatchKeyguardLockedStateState();
+ dispatchKeyguardLockedState();
}
@Override
@@ -3248,7 +3249,7 @@
+ " permission required to read keyguard visibility");
}
- private void dispatchKeyguardLockedStateState() {
+ private void dispatchKeyguardLockedState() {
mH.post(() -> {
final boolean isKeyguardLocked = mPolicy.isKeyguardShowing();
if (mDispatchedKeyguardLockedState == isKeyguardLocked) {
@@ -8983,4 +8984,24 @@
return Bitmap.wrapHardwareBuffer(taskSnapshot.getHardwareBuffer(),
taskSnapshot.getColorSpace());
}
+
+ @Override
+ public void setRecentsAppBehindSystemBars(boolean behindSystemBars) {
+ if (!checkCallingPermission(START_TASKS_FROM_RECENTS, "setRecentsAppBehindSystemBars()")) {
+ throw new SecurityException("Requires START_TASKS_FROM_RECENTS permission");
+ }
+ final long token = Binder.clearCallingIdentity();
+ try {
+ synchronized (mGlobalLock) {
+ final Task recentsApp = mRoot.getTask(task -> task.isActivityTypeHomeOrRecents()
+ && task.getTopVisibleActivity() != null);
+ if (recentsApp != null) {
+ recentsApp.getTask().setCanAffectSystemUiFlags(behindSystemBars);
+ mWindowPlacerLocked.requestTraversal();
+ }
+ }
+ } finally {
+ Binder.restoreCallingIdentity(token);
+ }
+ }
}
diff --git a/services/core/java/com/android/server/wm/WindowOrganizerController.java b/services/core/java/com/android/server/wm/WindowOrganizerController.java
index c70a40c..ce27d73 100644
--- a/services/core/java/com/android/server/wm/WindowOrganizerController.java
+++ b/services/core/java/com/android/server/wm/WindowOrganizerController.java
@@ -21,11 +21,13 @@
import static android.view.Display.DEFAULT_DISPLAY;
import static android.window.WindowContainerTransaction.Change.CHANGE_BOUNDS_TRANSACTION;
import static android.window.WindowContainerTransaction.Change.CHANGE_BOUNDS_TRANSACTION_RECT;
+import static android.window.WindowContainerTransaction.HierarchyOp.HIERARCHY_OP_TYPE_ADD_RECT_INSETS_PROVIDER;
import static android.window.WindowContainerTransaction.HierarchyOp.HIERARCHY_OP_TYPE_CHILDREN_TASKS_REPARENT;
import static android.window.WindowContainerTransaction.HierarchyOp.HIERARCHY_OP_TYPE_CREATE_TASK_FRAGMENT;
import static android.window.WindowContainerTransaction.HierarchyOp.HIERARCHY_OP_TYPE_DELETE_TASK_FRAGMENT;
import static android.window.WindowContainerTransaction.HierarchyOp.HIERARCHY_OP_TYPE_LAUNCH_TASK;
import static android.window.WindowContainerTransaction.HierarchyOp.HIERARCHY_OP_TYPE_PENDING_INTENT;
+import static android.window.WindowContainerTransaction.HierarchyOp.HIERARCHY_OP_TYPE_REMOVE_INSETS_PROVIDER;
import static android.window.WindowContainerTransaction.HierarchyOp.HIERARCHY_OP_TYPE_REORDER;
import static android.window.WindowContainerTransaction.HierarchyOp.HIERARCHY_OP_TYPE_REPARENT;
import static android.window.WindowContainerTransaction.HierarchyOp.HIERARCHY_OP_TYPE_REPARENT_ACTIVITY_TO_TASK_FRAGMENT;
@@ -895,6 +897,17 @@
taskDisplayArea.moveRootTaskBehindRootTask(thisTask.getRootTask(), restoreAt);
break;
}
+ case HIERARCHY_OP_TYPE_ADD_RECT_INSETS_PROVIDER:
+ final Rect insetsProviderWindowContainer = hop.getInsetsProviderFrame();
+ final WindowContainer receiverWindowContainer =
+ WindowContainer.fromBinder(hop.getContainer());
+ receiverWindowContainer.addLocalRectInsetsSourceProvider(
+ insetsProviderWindowContainer, hop.getInsetsTypes());
+ break;
+ case HIERARCHY_OP_TYPE_REMOVE_INSETS_PROVIDER:
+ WindowContainer.fromBinder(hop.getContainer())
+ .removeLocalInsetsSourceProvider(hop.getInsetsTypes());
+ break;
}
return effects;
}
diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
index 1ac0c26..5cda9ea 100644
--- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
+++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
@@ -8610,20 +8610,23 @@
admin.getPackageName(), userId, "set-device-owner");
Slogf.i(LOG_TAG, "Device owner set: " + admin + " on user " + userId);
-
- if (setProfileOwnerOnCurrentUserIfNecessary
- && mInjector.userManagerIsHeadlessSystemUserMode()) {
- int currentForegroundUser = getCurrentForegroundUserId();
- Slogf.i(LOG_TAG, "setDeviceOwner(): setting " + admin
- + " as profile owner on user " + currentForegroundUser);
- // Sets profile owner on current foreground user since
- // the human user will complete the DO setup workflow from there.
- manageUserUnchecked(/* deviceOwner= */ admin, /* profileOwner= */ admin,
- /* managedUser= */ currentForegroundUser, /* adminExtras= */ null,
- /* showDisclaimer= */ false);
- }
- return true;
}
+
+ if (setProfileOwnerOnCurrentUserIfNecessary
+ && mInjector.userManagerIsHeadlessSystemUserMode()) {
+ int currentForegroundUser;
+ synchronized (getLockObject()) {
+ currentForegroundUser = getCurrentForegroundUserId();
+ }
+ Slogf.i(LOG_TAG, "setDeviceOwner(): setting " + admin
+ + " as profile owner on user " + currentForegroundUser);
+ // Sets profile owner on current foreground user since
+ // the human user will complete the DO setup workflow from there.
+ manageUserUnchecked(/* deviceOwner= */ admin, /* profileOwner= */ admin,
+ /* managedUser= */ currentForegroundUser, /* adminExtras= */ null,
+ /* showDisclaimer= */ false);
+ }
+ return true;
}
@Override
@@ -10853,7 +10856,7 @@
final int userHandle = user.getIdentifier();
final long id = mInjector.binderClearCallingIdentity();
try {
- maybeInstallDeviceManagerRoleHolderInUser(userHandle);
+ maybeInstallDevicePolicyManagementRoleHolderInUser(userHandle);
manageUserUnchecked(admin, profileOwner, userHandle, adminExtras,
/* showDisclaimer= */ true);
@@ -17732,7 +17735,7 @@
startTime,
callerPackage);
- maybeInstallDeviceManagerRoleHolderInUser(userInfo.id);
+ maybeInstallDevicePolicyManagementRoleHolderInUser(userInfo.id);
installExistingAdminPackage(userInfo.id, admin.getPackageName());
if (!enableAdminAndSetProfileOwner(
@@ -17800,24 +17803,25 @@
private void onCreateAndProvisionManagedProfileCompleted(
ManagedProfileProvisioningParams provisioningParams) {}
- private void maybeInstallDeviceManagerRoleHolderInUser(int targetUserId) {
- String deviceManagerRoleHolderPackageName = getDeviceManagerRoleHolderPackageName(mContext);
- if (deviceManagerRoleHolderPackageName == null) {
- Slogf.d(LOG_TAG, "No device manager role holder specified.");
+ private void maybeInstallDevicePolicyManagementRoleHolderInUser(int targetUserId) {
+ String devicePolicyManagerRoleHolderPackageName =
+ getDevicePolicyManagementRoleHolderPackageName(mContext);
+ if (devicePolicyManagerRoleHolderPackageName == null) {
+ Slogf.d(LOG_TAG, "No device policy management role holder specified.");
return;
}
try {
if (mIPackageManager.isPackageAvailable(
- deviceManagerRoleHolderPackageName, targetUserId)) {
- Slogf.d(LOG_TAG, "The device manager role holder "
- + deviceManagerRoleHolderPackageName + " is already installed in "
+ devicePolicyManagerRoleHolderPackageName, targetUserId)) {
+ Slogf.d(LOG_TAG, "The device policy management role holder "
+ + devicePolicyManagerRoleHolderPackageName + " is already installed in "
+ "user " + targetUserId);
return;
}
- Slogf.d(LOG_TAG, "Installing the device manager role holder "
- + deviceManagerRoleHolderPackageName + " in user " + targetUserId);
+ Slogf.d(LOG_TAG, "Installing the device policy management role holder "
+ + devicePolicyManagerRoleHolderPackageName + " in user " + targetUserId);
mIPackageManager.installExistingPackageAsUser(
- deviceManagerRoleHolderPackageName,
+ devicePolicyManagerRoleHolderPackageName,
targetUserId,
PackageManager.INSTALL_ALL_WHITELIST_RESTRICTED_PERMISSIONS,
PackageManager.INSTALL_REASON_POLICY,
@@ -17827,10 +17831,10 @@
}
}
- private String getDeviceManagerRoleHolderPackageName(Context context) {
+ private String getDevicePolicyManagementRoleHolderPackageName(Context context) {
RoleManager roleManager = context.getSystemService(RoleManager.class);
List<String> roleHolders =
- roleManager.getRoleHolders(RoleManager.ROLE_DEVICE_MANAGER);
+ roleManager.getRoleHolders(RoleManager.ROLE_DEVICE_POLICY_MANAGEMENT);
if (roleHolders.isEmpty()) {
return null;
}
diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/OverlayPackagesProvider.java b/services/devicepolicy/java/com/android/server/devicepolicy/OverlayPackagesProvider.java
index 598f9e8..f3b164c 100644
--- a/services/devicepolicy/java/com/android/server/devicepolicy/OverlayPackagesProvider.java
+++ b/services/devicepolicy/java/com/android/server/devicepolicy/OverlayPackagesProvider.java
@@ -94,7 +94,7 @@
String getActiveApexPackageNameContainingPackage(String packageName);
- String getDeviceManagerRoleHolderPackageName(Context context);
+ String getDevicePolicyManagementRoleHolderPackageName(Context context);
}
private static final class DefaultInjector implements Injector {
@@ -110,11 +110,11 @@
}
@Override
- public String getDeviceManagerRoleHolderPackageName(Context context) {
+ public String getDevicePolicyManagementRoleHolderPackageName(Context context) {
return Binder.withCleanCallingIdentity(() -> {
RoleManager roleManager = context.getSystemService(RoleManager.class);
List<String> roleHolders =
- roleManager.getRoleHolders(RoleManager.ROLE_DEVICE_MANAGER);
+ roleManager.getRoleHolders(RoleManager.ROLE_DEVICE_POLICY_MANAGEMENT);
if (roleHolders.isEmpty()) {
return null;
}
@@ -166,7 +166,7 @@
private Set<String> getDeviceManagerRoleHolders() {
HashSet<String> result = new HashSet<>();
String deviceManagerRoleHolderPackageName =
- mInjector.getDeviceManagerRoleHolderPackageName(mContext);
+ mInjector.getDevicePolicyManagementRoleHolderPackageName(mContext);
if (deviceManagerRoleHolderPackageName != null) {
result.add(deviceManagerRoleHolderPackageName);
}
diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java
index a14e14b..4ff53ea 100644
--- a/services/java/com/android/server/SystemServer.java
+++ b/services/java/com/android/server/SystemServer.java
@@ -422,8 +422,8 @@
private static final String SAFETY_CENTER_SERVICE_CLASS =
"com.android.safetycenter.SafetyCenterService";
- private static final String SUPPLEMENTALPROCESS_SERVICE_CLASS =
- "com.android.server.supplementalprocess.SupplementalProcessManagerService$Lifecycle";
+ private static final String SDK_SANDBOX_MANAGER_SERVICE_CLASS =
+ "com.android.server.sdksandbox.SdkSandboxManagerService$Lifecycle";
private static final String TETHERING_CONNECTOR_CLASS = "android.net.ITetheringConnector";
@@ -2605,9 +2605,9 @@
mSystemServiceManager.startService(IncidentCompanionService.class);
t.traceEnd();
- // Supplemental Process
- t.traceBegin("StartSupplementalProcessManagerService");
- mSystemServiceManager.startService(SUPPLEMENTALPROCESS_SERVICE_CLASS);
+ // SdkSandboxManagerService
+ t.traceBegin("StarSdkSandboxManagerService");
+ mSystemServiceManager.startService(SDK_SANDBOX_MANAGER_SERVICE_CLASS);
t.traceEnd();
if (safeMode) {
diff --git a/services/tests/mockingservicestests/Android.bp b/services/tests/mockingservicestests/Android.bp
index 3e60af3..670c159 100644
--- a/services/tests/mockingservicestests/Android.bp
+++ b/services/tests/mockingservicestests/Android.bp
@@ -52,7 +52,7 @@
"service-blobstore",
"service-jobscheduler",
"service-permission.impl",
- "service-supplementalprocess.impl",
+ "service-sdksandbox.impl",
"services.companion",
"services.core",
"services.devicepolicy",
diff --git a/services/tests/mockingservicestests/src/com/android/server/pm/MockSystem.kt b/services/tests/mockingservicestests/src/com/android/server/pm/MockSystem.kt
index 6510cd1..cb9f003 100644
--- a/services/tests/mockingservicestests/src/com/android/server/pm/MockSystem.kt
+++ b/services/tests/mockingservicestests/src/com/android/server/pm/MockSystem.kt
@@ -70,7 +70,7 @@
import com.android.server.pm.pkg.parsing.ParsingPackageUtils
import com.android.server.pm.resolution.ComponentResolver
import com.android.server.pm.verify.domain.DomainVerificationManagerInternal
-import com.android.server.supplementalprocess.SupplementalProcessManagerLocal
+import com.android.server.sdksandbox.SdkSandboxManagerLocal
import com.android.server.testutils.TestHandler
import com.android.server.testutils.mock
import com.android.server.testutils.nullable
@@ -577,7 +577,7 @@
1L, systemPartitions[0].privAppFolder,
withPackage = { pkg: PackageImpl ->
val applicationInfo: ApplicationInfo = createBasicApplicationInfo(pkg)
- mockQueryServices(SupplementalProcessManagerLocal.SERVICE_INTERFACE,
+ mockQueryServices(SdkSandboxManagerLocal.SERVICE_INTERFACE,
createBasicServiceInfo(
pkg, applicationInfo, "SupplementalProcessService"))
pkg
diff --git a/services/tests/servicestests/src/com/android/server/backup/restore/FullRestoreEngineTest.java b/services/tests/servicestests/src/com/android/server/backup/restore/FullRestoreEngineTest.java
deleted file mode 100644
index 049c745..0000000
--- a/services/tests/servicestests/src/com/android/server/backup/restore/FullRestoreEngineTest.java
+++ /dev/null
@@ -1,150 +0,0 @@
-/*
- * Copyright (C) 2022 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.server.backup.restore;
-
-import static com.google.common.truth.Truth.assertWithMessage;
-
-import android.app.backup.BackupAgent;
-import android.platform.test.annotations.Presubmit;
-import android.system.OsConstants;
-
-import androidx.test.runner.AndroidJUnit4;
-
-import com.android.server.backup.FileMetadata;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-@Presubmit
-@RunWith(AndroidJUnit4.class)
-public class FullRestoreEngineTest {
- private static final String DEFAULT_PACKAGE_NAME = "package";
- private static final String DEFAULT_DOMAIN_NAME = "domain";
- private static final String NEW_PACKAGE_NAME = "new_package";
- private static final String NEW_DOMAIN_NAME = "new_domain";
-
- private FullRestoreEngine mRestoreEngine;
-
- @Before
- public void setUp() {
- mRestoreEngine = new FullRestoreEngine();
- }
-
- @Test
- public void shouldSkipReadOnlyDir_skipsAllReadonlyDirsAndTheirChildren() {
- // Create the file tree.
- TestFile[] testFiles = new TestFile[] {
- TestFile.dir("root"),
- TestFile.file("root/auth_token"),
- TestFile.dir("root/media"),
- TestFile.file("root/media/picture1.png"),
- TestFile.file("root/push_token.txt"),
- TestFile.dir("root/read-only-dir-1").markReadOnly().expectSkipped(),
- TestFile.dir("root/read-only-dir-1/writable-subdir").expectSkipped(),
- TestFile.file("root/read-only-dir-1/writable-subdir/writable-file").expectSkipped(),
- TestFile.dir("root/read-only-dir-1/writable-subdir/read-only-subdir-2")
- .markReadOnly().expectSkipped(),
- TestFile.file("root/read-only-dir-1/writable-file").expectSkipped(),
- TestFile.file("root/random-stuff.txt"),
- TestFile.dir("root/database"),
- TestFile.file("root/database/users.db"),
- TestFile.dir("root/read-only-dir-2").markReadOnly().expectSkipped(),
- TestFile.file("root/read-only-dir-2/writable-file-1").expectSkipped(),
- TestFile.file("root/read-only-dir-2/writable-file-2").expectSkipped(),
- };
-
- assertCorrectItemsAreSkipped(testFiles);
- }
-
- @Test
- public void shouldSkipReadOnlyDir_onlySkipsChildrenUnderTheSamePackage() {
- TestFile[] testFiles = new TestFile[]{
- TestFile.dir("read-only-dir").markReadOnly().expectSkipped(),
- TestFile.file("read-only-dir/file").expectSkipped(),
- TestFile.file("read-only-dir/file-from-different-package")
- .setPackage(NEW_PACKAGE_NAME),
- };
-
- assertCorrectItemsAreSkipped(testFiles);
- }
-
- @Test
- public void shouldSkipReadOnlyDir_onlySkipsChildrenUnderTheSameDomain() {
- TestFile[] testFiles = new TestFile[]{
- TestFile.dir("read-only-dir").markReadOnly().expectSkipped(),
- TestFile.file("read-only-dir/file").expectSkipped(),
- TestFile.file("read-only-dir/file-from-different-domain")
- .setDomain(NEW_DOMAIN_NAME),
- };
-
- assertCorrectItemsAreSkipped(testFiles);
- }
-
- private void assertCorrectItemsAreSkipped(TestFile[] testFiles) {
- // Verify all directories marked with .expectSkipped are skipped.
- for (TestFile testFile : testFiles) {
- boolean actualExcluded = mRestoreEngine.shouldSkipReadOnlyDir(testFile.mMetadata);
- boolean expectedExcluded = testFile.mShouldSkip;
- assertWithMessage(testFile.mMetadata.path).that(actualExcluded).isEqualTo(
- expectedExcluded);
- }
- }
-
- private static class TestFile {
- private final FileMetadata mMetadata;
- private boolean mShouldSkip;
-
- static TestFile dir(String path) {
- return new TestFile(path, BackupAgent.TYPE_DIRECTORY);
- }
-
- static TestFile file(String path) {
- return new TestFile(path, BackupAgent.TYPE_FILE);
- }
-
- TestFile markReadOnly() {
- mMetadata.mode = 0;
- return this;
- }
-
- TestFile expectSkipped() {
- mShouldSkip = true;
- return this;
- }
-
- TestFile setPackage(String packageName) {
- mMetadata.packageName = packageName;
- return this;
- }
-
- TestFile setDomain(String domain) {
- mMetadata.domain = domain;
- return this;
- }
-
- private TestFile(String path, int type) {
- FileMetadata metadata = new FileMetadata();
- metadata.path = path;
- metadata.type = type;
- metadata.packageName = DEFAULT_PACKAGE_NAME;
- metadata.domain = DEFAULT_DOMAIN_NAME;
- metadata.mode = OsConstants.S_IWUSR; // Mark as writable.
- mMetadata = metadata;
- }
- }
-}
diff --git a/services/tests/servicestests/src/com/android/server/devicepolicy/OverlayPackagesProviderTest.java b/services/tests/servicestests/src/com/android/server/devicepolicy/OverlayPackagesProviderTest.java
index 533fb2d..4f6fc3d 100644
--- a/services/tests/servicestests/src/com/android/server/devicepolicy/OverlayPackagesProviderTest.java
+++ b/services/tests/servicestests/src/com/android/server/devicepolicy/OverlayPackagesProviderTest.java
@@ -309,7 +309,7 @@
@Test
public void testGetNonRequiredApps_managedProfile_roleHolder_works() {
- when(mInjector.getDeviceManagerRoleHolderPackageName(any()))
+ when(mInjector.getDevicePolicyManagementRoleHolderPackageName(any()))
.thenReturn(ROLE_HOLDER_PACKAGE_NAME);
setSystemAppsWithLauncher("package1", "package2", ROLE_HOLDER_PACKAGE_NAME);
@@ -319,7 +319,7 @@
@Test
public void testGetNonRequiredApps_managedDevice_roleHolder_works() {
- when(mInjector.getDeviceManagerRoleHolderPackageName(any()))
+ when(mInjector.getDevicePolicyManagementRoleHolderPackageName(any()))
.thenReturn(ROLE_HOLDER_PACKAGE_NAME);
setSystemAppsWithLauncher("package1", "package2", ROLE_HOLDER_PACKAGE_NAME);
diff --git a/services/tests/servicestests/src/com/android/server/systemconfig/SystemConfigTest.java b/services/tests/servicestests/src/com/android/server/systemconfig/SystemConfigTest.java
index eeaf781..bfdffc0 100644
--- a/services/tests/servicestests/src/com/android/server/systemconfig/SystemConfigTest.java
+++ b/services/tests/servicestests/src/com/android/server/systemconfig/SystemConfigTest.java
@@ -39,9 +39,11 @@
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
import java.io.BufferedWriter;
import java.io.File;
+import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Arrays;
@@ -137,13 +139,14 @@
new ArraySet<>(Arrays.asList("GUEST", "PROFILE")));
final File folder1 = createTempSubfolder("folder1");
- createTempFile(folder1, "permFile1.xml", contents1);
+ createTempFile(folder1, "permissionFile1.xml", contents1);
final File folder2 = createTempSubfolder("folder2");
- createTempFile(folder2, "permFile2.xml", contents2);
+ createTempFile(folder2, "permissionFile2.xml", contents2);
- // Also, make a third file, but with the name folder1/permFile2.xml, to prove no conflicts.
- createTempFile(folder1, "permFile2.xml", contents3);
+ // Also, make a third file, but with the name folder1/permissionFile2.xml, to prove no
+ // conflicts.
+ createTempFile(folder1, "permissionFile2.xml", contents3);
readPermissions(folder1, /* No permission needed anyway */ 0);
readPermissions(folder2, /* No permission needed anyway */ 0);
@@ -333,6 +336,91 @@
assertThat(mSysConfig.getAllowedVendorApexes()).isEmpty();
}
+ @Test
+ public void readApexPrivAppPermissions_addAllPermissions()
+ throws Exception {
+ final String contents =
+ "<privapp-permissions package=\"com.android.apk_in_apex\">"
+ + "<permission name=\"android.permission.FOO\"/>"
+ + "<deny-permission name=\"android.permission.BAR\"/>"
+ + "</privapp-permissions>";
+ File apexDir = createTempSubfolder("apex");
+ File permissionFile = createTempFile(
+ createTempSubfolder("apex/com.android.my_module/etc/permissions"),
+ "permissions.xml", contents);
+ XmlPullParser parser = readXmlUntilStartTag(permissionFile);
+
+ mSysConfig.readApexPrivAppPermissions(parser, permissionFile, apexDir.toPath());
+
+ assertThat(mSysConfig.getApexPrivAppPermissions("com.android.my_module",
+ "com.android.apk_in_apex"))
+ .containsExactly("android.permission.FOO");
+ assertThat(mSysConfig.getApexPrivAppDenyPermissions("com.android.my_module",
+ "com.android.apk_in_apex"))
+ .containsExactly("android.permission.BAR");
+ }
+
+ @Test
+ public void pruneVendorApexPrivappAllowlists_removeVendor()
+ throws Exception {
+ File apexDir = createTempSubfolder("apex");
+
+ // Read non-vendor apex permission allowlists
+ final String allowlistNonVendorContents =
+ "<privapp-permissions package=\"com.android.apk_in_non_vendor_apex\">"
+ + "<permission name=\"android.permission.FOO\"/>"
+ + "<deny-permission name=\"android.permission.BAR\"/>"
+ + "</privapp-permissions>";
+ File nonVendorPermDir =
+ createTempSubfolder("apex/com.android.non_vendor/etc/permissions");
+ File nonVendorPermissionFile =
+ createTempFile(nonVendorPermDir, "permissions.xml", allowlistNonVendorContents);
+ XmlPullParser nonVendorParser = readXmlUntilStartTag(nonVendorPermissionFile);
+ mSysConfig.readApexPrivAppPermissions(nonVendorParser, nonVendorPermissionFile,
+ apexDir.toPath());
+
+ // Read vendor apex permission allowlists
+ final String allowlistVendorContents =
+ "<privapp-permissions package=\"com.android.apk_in_vendor_apex\">"
+ + "<permission name=\"android.permission.BAZ\"/>"
+ + "<deny-permission name=\"android.permission.BAT\"/>"
+ + "</privapp-permissions>";
+ File vendorPermissionFile =
+ createTempFile(createTempSubfolder("apex/com.android.vendor/etc/permissions"),
+ "permissions.xml", allowlistNonVendorContents);
+ XmlPullParser vendorParser = readXmlUntilStartTag(vendorPermissionFile);
+ mSysConfig.readApexPrivAppPermissions(vendorParser, vendorPermissionFile,
+ apexDir.toPath());
+
+ // Read allowed vendor apex list
+ final String allowedVendorContents =
+ "<config>\n"
+ + " <allowed-vendor-apex package=\"com.android.vendor\" "
+ + "installerPackage=\"com.installer\" />\n"
+ + "</config>";
+ final File allowedVendorFolder = createTempSubfolder("folder");
+ createTempFile(allowedVendorFolder, "vendor-apex-allowlist.xml", allowedVendorContents);
+ readPermissions(allowedVendorFolder, /* Grant all permission flags */ ~0);
+
+ // Finally, prune non-vendor allowlists.
+ // There is no guarantee in which order the above reads will be done, however pruning
+ // will always happen last.
+ mSysConfig.pruneVendorApexPrivappAllowlists();
+
+ assertThat(mSysConfig.getApexPrivAppPermissions("com.android.non_vendor",
+ "com.android.apk_in_non_vendor_apex"))
+ .containsExactly("android.permission.FOO");
+ assertThat(mSysConfig.getApexPrivAppDenyPermissions("com.android.non_vendor",
+ "com.android.apk_in_non_vendor_apex"))
+ .containsExactly("android.permission.BAR");
+ assertThat(mSysConfig.getApexPrivAppPermissions("com.android.vendor",
+ "com.android.apk_in_vendor_apex"))
+ .isNull();
+ assertThat(mSysConfig.getApexPrivAppDenyPermissions("com.android.vendor",
+ "com.android.apk_in_vendor_apex"))
+ .isNull();
+ }
+
/**
* Tests that readPermissions works correctly for a library with on-bootclasspath-before
* and on-bootclasspath-since.
@@ -492,6 +580,25 @@
}
/**
+ * Create an {@link XmlPullParser} for {@param permissionFile} and begin parsing it until
+ * reaching the root tag.
+ */
+ private XmlPullParser readXmlUntilStartTag(File permissionFile)
+ throws IOException, XmlPullParserException {
+ FileReader permReader = new FileReader(permissionFile);
+ XmlPullParser parser = Xml.newPullParser();
+ parser.setInput(permReader);
+ int type;
+ do {
+ type = parser.next();
+ } while (type != parser.START_TAG && type != parser.END_DOCUMENT);
+ if (type != parser.START_TAG) {
+ throw new XmlPullParserException("No start tag found");
+ }
+ return parser;
+ }
+
+ /**
* Creates folderName/fileName in the mTemporaryFolder and fills it with the contents.
*
* @param folderName subdirectory of mTemporaryFolder to put the file, creating if needed
@@ -500,7 +607,7 @@
private File createTempSubfolder(String folderName)
throws IOException {
File folder = new File(mTemporaryFolder.getRoot(), folderName);
- folder.mkdir();
+ folder.mkdirs();
return folder;
}
diff --git a/services/tests/servicestests/src/com/android/server/vibrator/DeviceVibrationEffectAdapterTest.java b/services/tests/servicestests/src/com/android/server/vibrator/DeviceVibrationEffectAdapterTest.java
index 5e9e16a..1a146f6 100644
--- a/services/tests/servicestests/src/com/android/server/vibrator/DeviceVibrationEffectAdapterTest.java
+++ b/services/tests/servicestests/src/com/android/server/vibrator/DeviceVibrationEffectAdapterTest.java
@@ -18,7 +18,10 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.when;
+import android.content.ComponentName;
+import android.content.pm.PackageManagerInternal;
import android.hardware.vibrator.IVibrator;
import android.os.Handler;
import android.os.VibrationEffect;
@@ -33,8 +36,14 @@
import androidx.test.InstrumentationRegistry;
+import com.android.server.LocalServices;
+
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import java.util.Arrays;
import java.util.stream.IntStream;
@@ -59,10 +68,19 @@
new VibratorInfo.FrequencyProfile(TEST_RESONANT_FREQUENCY, TEST_MIN_FREQUENCY,
TEST_FREQUENCY_RESOLUTION, TEST_AMPLITUDE_MAP);
+ @Rule public MockitoRule mMockitoRule = MockitoJUnit.rule();
+
+ @Mock private PackageManagerInternal mPackageManagerInternalMock;
+
private DeviceVibrationEffectAdapter mAdapter;
@Before
public void setUp() throws Exception {
+ when(mPackageManagerInternalMock.getSystemUiServiceComponent())
+ .thenReturn(new ComponentName("", ""));
+ LocalServices.removeServiceForTest(PackageManagerInternal.class);
+ LocalServices.addService(PackageManagerInternal.class, mPackageManagerInternalMock);
+
VibrationSettings vibrationSettings = new VibrationSettings(
InstrumentationRegistry.getContext(), new Handler(new TestLooper().getLooper()));
mAdapter = new DeviceVibrationEffectAdapter(vibrationSettings);
diff --git a/services/tests/servicestests/src/com/android/server/vibrator/VibrationScalerTest.java b/services/tests/servicestests/src/com/android/server/vibrator/VibrationScalerTest.java
index 8167710..0301e94 100644
--- a/services/tests/servicestests/src/com/android/server/vibrator/VibrationScalerTest.java
+++ b/services/tests/servicestests/src/com/android/server/vibrator/VibrationScalerTest.java
@@ -31,8 +31,10 @@
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
+import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.ContextWrapper;
+import android.content.pm.PackageManagerInternal;
import android.os.Handler;
import android.os.IExternalVibratorService;
import android.os.PowerManagerInternal;
@@ -76,6 +78,7 @@
@Rule public FakeSettingsProviderRule mSettingsProviderRule = FakeSettingsProvider.rule();
@Mock private PowerManagerInternal mPowerManagerInternalMock;
+ @Mock private PackageManagerInternal mPackageManagerInternalMock;
@Mock private VibrationConfig mVibrationConfigMock;
private TestLooper mTestLooper;
@@ -90,7 +93,11 @@
ContentResolver contentResolver = mSettingsProviderRule.mockContentResolver(mContextSpy);
when(mContextSpy.getContentResolver()).thenReturn(contentResolver);
+ when(mPackageManagerInternalMock.getSystemUiServiceComponent())
+ .thenReturn(new ComponentName("", ""));
+ LocalServices.removeServiceForTest(PackageManagerInternal.class);
+ LocalServices.addService(PackageManagerInternal.class, mPackageManagerInternalMock);
LocalServices.removeServiceForTest(PowerManagerInternal.class);
LocalServices.addService(PowerManagerInternal.class, mPowerManagerInternalMock);
diff --git a/services/tests/servicestests/src/com/android/server/vibrator/VibrationSettingsTest.java b/services/tests/servicestests/src/com/android/server/vibrator/VibrationSettingsTest.java
index 5d4ffbb..3cda2a5 100644
--- a/services/tests/servicestests/src/com/android/server/vibrator/VibrationSettingsTest.java
+++ b/services/tests/servicestests/src/com/android/server/vibrator/VibrationSettingsTest.java
@@ -47,13 +47,16 @@
import static org.mockito.Mockito.when;
import android.app.ActivityManager;
+import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.ContextWrapper;
import android.content.Intent;
+import android.content.pm.PackageManagerInternal;
import android.media.AudioManager;
import android.os.Handler;
import android.os.PowerManagerInternal;
import android.os.PowerSaveState;
+import android.os.Process;
import android.os.UserHandle;
import android.os.VibrationAttributes;
import android.os.VibrationEffect;
@@ -87,6 +90,7 @@
public class VibrationSettingsTest {
private static final int UID = 1;
+ private static final String SYSUI_PACKAGE_NAME = "sysui";
private static final PowerSaveState NORMAL_POWER_STATE = new PowerSaveState.Builder().build();
private static final PowerSaveState LOW_POWER_STATE = new PowerSaveState.Builder()
.setBatterySaverEnabled(true).build();
@@ -104,17 +108,13 @@
USAGE_TOUCH,
};
- @Rule
- public MockitoRule mMockitoRule = MockitoJUnit.rule();
- @Rule
- public FakeSettingsProviderRule mSettingsProviderRule = FakeSettingsProvider.rule();
+ @Rule public MockitoRule mMockitoRule = MockitoJUnit.rule();
+ @Rule public FakeSettingsProviderRule mSettingsProviderRule = FakeSettingsProvider.rule();
- @Mock
- private VibrationSettings.OnVibratorSettingsChanged mListenerMock;
- @Mock
- private PowerManagerInternal mPowerManagerInternalMock;
- @Mock
- private VibrationConfig mVibrationConfigMock;
+ @Mock private VibrationSettings.OnVibratorSettingsChanged mListenerMock;
+ @Mock private PowerManagerInternal mPowerManagerInternalMock;
+ @Mock private PackageManagerInternal mPackageManagerInternalMock;
+ @Mock private VibrationConfig mVibrationConfigMock;
private TestLooper mTestLooper;
private ContextWrapper mContextSpy;
@@ -129,14 +129,17 @@
ContentResolver contentResolver = mSettingsProviderRule.mockContentResolver(mContextSpy);
when(mContextSpy.getContentResolver()).thenReturn(contentResolver);
-
doAnswer(invocation -> {
mRegisteredPowerModeListener = invocation.getArgument(0);
return null;
}).when(mPowerManagerInternalMock).registerLowPowerModeObserver(any());
+ when(mPackageManagerInternalMock.getSystemUiServiceComponent())
+ .thenReturn(new ComponentName(SYSUI_PACKAGE_NAME, ""));
LocalServices.removeServiceForTest(PowerManagerInternal.class);
LocalServices.addService(PowerManagerInternal.class, mPowerManagerInternalMock);
+ LocalServices.removeServiceForTest(PackageManagerInternal.class);
+ LocalServices.addService(PackageManagerInternal.class, mPackageManagerInternalMock);
setDefaultIntensity(VIBRATION_INTENSITY_MEDIUM);
mAudioManager = mContextSpy.getSystemService(AudioManager.class);
@@ -285,7 +288,7 @@
}
@Test
- public void shouldIgnoreVibration_withRingerModeSilent_ignoresRingtoneAndTouch() {
+ public void shouldIgnoreVibration_withRingerModeSilent_ignoresRingtoneOnly() {
// Vibrating settings on are overruled by ringer mode.
setUserSetting(Settings.System.HAPTIC_FEEDBACK_ENABLED, 1);
setUserSetting(Settings.System.VIBRATE_WHEN_RINGING, 1);
@@ -293,7 +296,7 @@
setRingerMode(AudioManager.RINGER_MODE_SILENT);
for (int usage : ALL_USAGES) {
- if (usage == USAGE_RINGTONE || usage == USAGE_TOUCH) {
+ if (usage == USAGE_RINGTONE) {
assertVibrationIgnoredForUsage(usage, Vibration.Status.IGNORED_FOR_RINGER_MODE);
} else {
assertVibrationNotIgnoredForUsage(usage);
@@ -472,6 +475,55 @@
}
@Test
+ public void shouldCancelVibrationOnScreenOff_withNonSystemPackageAndUid_returnsAlwaysTrue() {
+ for (int usage : ALL_USAGES) {
+ assertTrue(mVibrationSettings.shouldCancelVibrationOnScreenOff(UID, "some.app", usage));
+ }
+ }
+
+ @Test
+ public void shouldCancelVibrationOnScreenOff_withUidZero_returnsFalseForTouchAndHardware() {
+ for (int usage : ALL_USAGES) {
+ if (usage == USAGE_TOUCH || usage == USAGE_HARDWARE_FEEDBACK
+ || usage == USAGE_PHYSICAL_EMULATION) {
+ assertFalse(mVibrationSettings.shouldCancelVibrationOnScreenOff(
+ /* uid= */ 0, "", usage));
+ } else {
+ assertTrue(mVibrationSettings.shouldCancelVibrationOnScreenOff(
+ /* uid= */ 0, "", usage));
+ }
+ }
+ }
+
+ @Test
+ public void shouldCancelVibrationOnScreenOff_withSystemUid_returnsFalseForTouchAndHardware() {
+ for (int usage : ALL_USAGES) {
+ if (usage == USAGE_TOUCH || usage == USAGE_HARDWARE_FEEDBACK
+ || usage == USAGE_PHYSICAL_EMULATION) {
+ assertFalse(mVibrationSettings.shouldCancelVibrationOnScreenOff(
+ Process.SYSTEM_UID, "", usage));
+ } else {
+ assertTrue(mVibrationSettings.shouldCancelVibrationOnScreenOff(
+ Process.SYSTEM_UID, "", usage));
+ }
+ }
+ }
+
+ @Test
+ public void shouldCancelVibrationOnScreenOff_withSysUi_returnsFalseForTouchAndHardware() {
+ for (int usage : ALL_USAGES) {
+ if (usage == USAGE_TOUCH || usage == USAGE_HARDWARE_FEEDBACK
+ || usage == USAGE_PHYSICAL_EMULATION) {
+ assertFalse(mVibrationSettings.shouldCancelVibrationOnScreenOff(
+ UID, SYSUI_PACKAGE_NAME, usage));
+ } else {
+ assertTrue(mVibrationSettings.shouldCancelVibrationOnScreenOff(
+ UID, SYSUI_PACKAGE_NAME, usage));
+ }
+ }
+ }
+
+ @Test
public void getDefaultIntensity_returnsIntensityFromVibratorConfig() {
setDefaultIntensity(VIBRATION_INTENSITY_HIGH);
setUserSetting(Settings.System.ALARM_VIBRATION_INTENSITY, VIBRATION_INTENSITY_OFF);
diff --git a/services/tests/servicestests/src/com/android/server/vibrator/VibrationThreadTest.java b/services/tests/servicestests/src/com/android/server/vibrator/VibrationThreadTest.java
index 3d24a81..0590d7d 100644
--- a/services/tests/servicestests/src/com/android/server/vibrator/VibrationThreadTest.java
+++ b/services/tests/servicestests/src/com/android/server/vibrator/VibrationThreadTest.java
@@ -35,7 +35,9 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import android.content.ComponentName;
import android.content.Context;
+import android.content.pm.PackageManagerInternal;
import android.hardware.vibrator.Braking;
import android.hardware.vibrator.IVibrator;
import android.hardware.vibrator.IVibratorManager;
@@ -61,6 +63,8 @@
import androidx.test.InstrumentationRegistry;
+import com.android.server.LocalServices;
+
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
@@ -94,17 +98,13 @@
private static final VibrationAttributes ATTRS = new VibrationAttributes.Builder().build();
private static final int TEST_RAMP_STEP_DURATION = 5;
- @Rule
- public MockitoRule mMockitoRule = MockitoJUnit.rule();
+ @Rule public MockitoRule mMockitoRule = MockitoJUnit.rule();
- @Mock
- private VibrationThread.VibratorManagerHooks mManagerHooks;
- @Mock
- private VibratorController.OnVibrationCompleteListener mControllerCallbacks;
- @Mock
- private IBinder mVibrationToken;
- @Mock
- private VibrationConfig mVibrationConfigMock;
+ @Mock private PackageManagerInternal mPackageManagerInternalMock;
+ @Mock private VibrationThread.VibratorManagerHooks mManagerHooks;
+ @Mock private VibratorController.OnVibrationCompleteListener mControllerCallbacks;
+ @Mock private IBinder mVibrationToken;
+ @Mock private VibrationConfig mVibrationConfigMock;
private final Map<Integer, FakeVibratorControllerProvider> mVibratorProviders = new HashMap<>();
private VibrationSettings mVibrationSettings;
@@ -123,6 +123,11 @@
when(mVibrationConfigMock.getDefaultVibrationIntensity(anyInt()))
.thenReturn(Vibrator.VIBRATION_INTENSITY_MEDIUM);
when(mVibrationConfigMock.getRampStepDurationMs()).thenReturn(TEST_RAMP_STEP_DURATION);
+ when(mPackageManagerInternalMock.getSystemUiServiceComponent())
+ .thenReturn(new ComponentName("", ""));
+
+ LocalServices.removeServiceForTest(PackageManagerInternal.class);
+ LocalServices.addService(PackageManagerInternal.class, mPackageManagerInternalMock);
Context context = InstrumentationRegistry.getContext();
mVibrationSettings = new VibrationSettings(context, new Handler(mTestLooper.getLooper()),
diff --git a/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java b/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java
index b3d6b3e..2ea0bdc 100644
--- a/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java
@@ -24,6 +24,7 @@
import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM;
import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
import static android.app.WindowConfiguration.WINDOWING_MODE_MULTI_WINDOW;
+import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;
import static android.content.pm.ActivityInfo.CONFIG_ORIENTATION;
import static android.content.pm.ActivityInfo.CONFIG_SCREEN_LAYOUT;
import static android.content.pm.ActivityInfo.FLAG_SUPPORTS_PICTURE_IN_PICTURE;
@@ -54,6 +55,7 @@
import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
import static android.view.WindowManager.TRANSIT_CLOSE;
import static android.view.WindowManager.TRANSIT_OLD_ACTIVITY_OPEN;
+import static android.view.WindowManager.TRANSIT_PIP;
import static android.window.StartingWindowInfo.TYPE_PARAMETER_LEGACY_SPLASH_SCREEN;
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
@@ -3397,6 +3399,24 @@
assertFalse(activity.mVisibleRequested);
}
+ @Test
+ public void testShellTransitionTaskWindowingModeChange() {
+ final ActivityRecord activity = createActivityWithTask();
+ final Task task = activity.getTask();
+ task.setWindowingMode(WINDOWING_MODE_FULLSCREEN);
+
+ assertTrue(activity.isVisible());
+ assertTrue(activity.isVisibleRequested());
+ assertEquals(WINDOWING_MODE_FULLSCREEN, activity.getWindowingMode());
+
+ registerTestTransitionPlayer();
+ task.mTransitionController.requestTransitionIfNeeded(TRANSIT_PIP, task);
+ task.setWindowingMode(WINDOWING_MODE_PINNED);
+
+ // Collect activity in the transition if the Task windowing mode is going to change.
+ assertTrue(activity.inTransition());
+ }
+
private ICompatCameraControlCallback getCompatCameraControlCallback() {
return new ICompatCameraControlCallback.Stub() {
@Override
diff --git a/services/tests/wmtests/src/com/android/server/wm/ActivityStartInterceptorTest.java b/services/tests/wmtests/src/com/android/server/wm/ActivityStartInterceptorTest.java
index 55d6df9..0c8394e 100644
--- a/services/tests/wmtests/src/com/android/server/wm/ActivityStartInterceptorTest.java
+++ b/services/tests/wmtests/src/com/android/server/wm/ActivityStartInterceptorTest.java
@@ -352,6 +352,6 @@
spyOn(callback);
mInterceptor.onActivityLaunched(null, null);
- verify(callback, times(1)).onActivityLaunched(any(), any());
+ verify(callback, times(1)).onActivityLaunched(any(), any(), any());
}
}
diff --git a/services/tests/wmtests/src/com/android/server/wm/RecentsAnimationControllerTest.java b/services/tests/wmtests/src/com/android/server/wm/RecentsAnimationControllerTest.java
index e091190..3c3351c0 100644
--- a/services/tests/wmtests/src/com/android/server/wm/RecentsAnimationControllerTest.java
+++ b/services/tests/wmtests/src/com/android/server/wm/RecentsAnimationControllerTest.java
@@ -16,6 +16,7 @@
package com.android.server.wm;
+import static android.content.res.Configuration.ORIENTATION_PORTRAIT;
import static android.view.Display.DEFAULT_DISPLAY;
import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
@@ -440,16 +441,26 @@
public void testCheckRotationAfterCleanup() {
mWm.setRecentsAnimationController(mController);
spyOn(mDisplayContent.mFixedRotationTransitionListener);
- doReturn(true).when(mDisplayContent.mFixedRotationTransitionListener)
- .isTopFixedOrientationRecentsAnimating();
+ final ActivityRecord recents = mock(ActivityRecord.class);
+ recents.mOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
+ doReturn(ORIENTATION_PORTRAIT).when(recents)
+ .getRequestedConfigurationOrientation(anyBoolean());
+ mDisplayContent.mFixedRotationTransitionListener.onStartRecentsAnimation(recents);
+
// Rotation update is skipped while the recents animation is running.
- assertFalse(mDisplayContent.getDisplayRotation().updateOrientation(DisplayContentTests
- .getRotatedOrientation(mDefaultDisplay), false /* forceUpdate */));
+ final DisplayRotation displayRotation = mDisplayContent.getDisplayRotation();
+ final int topOrientation = DisplayContentTests.getRotatedOrientation(mDefaultDisplay);
+ assertFalse(displayRotation.updateOrientation(topOrientation, false /* forceUpdate */));
+ assertEquals(recents.mOrientation, displayRotation.getLastOrientation());
final int prevRotation = mDisplayContent.getRotation();
mWm.cleanupRecentsAnimation(REORDER_MOVE_TO_ORIGINAL_POSITION);
- waitHandlerIdle(mWm.mH);
+
+ // In real case, it is called from RecentsAnimation#finishAnimation -> continueWindowLayout
+ // -> handleAppTransitionReady -> add FINISH_LAYOUT_REDO_CONFIG, and DisplayContent#
+ // applySurfaceChangesTransaction will call updateOrientation for FINISH_LAYOUT_REDO_CONFIG.
+ assertTrue(displayRotation.updateOrientation(topOrientation, false /* forceUpdate */));
// The display should be updated to the changed orientation after the animation is finished.
- assertNotEquals(mDisplayContent.getRotation(), prevRotation);
+ assertNotEquals(displayRotation.getRotation(), prevRotation);
}
@Test
diff --git a/services/tests/wmtests/src/com/android/server/wm/TransitionTests.java b/services/tests/wmtests/src/com/android/server/wm/TransitionTests.java
index 29289a4..501f0c4 100644
--- a/services/tests/wmtests/src/com/android/server/wm/TransitionTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/TransitionTests.java
@@ -19,6 +19,8 @@
import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD;
import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM;
import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
+import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
+import static android.view.WindowManager.LayoutParams.ROTATION_ANIMATION_SEAMLESS;
import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR;
import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL;
@@ -32,13 +34,17 @@
import static android.window.TransitionInfo.isIndependent;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
+import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assume.assumeFalse;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
@@ -557,11 +563,20 @@
@Test
public void testAppTransitionWithRotationChange() {
+ final TestTransitionPlayer player = registerTestTransitionPlayer();
+ final boolean useFixedRotation = !player.mController.useShellTransitionsRotation();
+ if (useFixedRotation) {
+ testFixedRotationOpen(player);
+ } else {
+ testShellRotationOpen(player);
+ }
+ }
+
+ private void testShellRotationOpen(TestTransitionPlayer player) {
final WindowState statusBar = createWindow(null, TYPE_STATUS_BAR, "statusBar");
makeWindowVisible(statusBar);
mDisplayContent.getDisplayPolicy().addWindowLw(statusBar, statusBar.mAttrs);
final ActivityRecord app = createActivityRecord(mDisplayContent);
- final TestTransitionPlayer player = registerTestTransitionPlayer();
final Transition transition = app.mTransitionController.createTransition(TRANSIT_OPEN);
app.mTransitionController.requestStartTransition(transition, app.getTask(),
null /* remoteTransition */, null /* displayChange */);
@@ -605,6 +620,85 @@
assertNull(mDisplayContent.getAsyncRotationController());
}
+ private void testFixedRotationOpen(TestTransitionPlayer player) {
+ final WindowState statusBar = createWindow(null, TYPE_STATUS_BAR, "statusBar");
+ makeWindowVisible(statusBar);
+ mDisplayContent.getDisplayPolicy().addWindowLw(statusBar, statusBar.mAttrs);
+ final ActivityRecord app = createActivityRecord(mDisplayContent);
+ final Transition transition = app.mTransitionController.createTransition(TRANSIT_OPEN);
+ app.mTransitionController.requestStartTransition(transition, app.getTask(),
+ null /* remoteTransition */, null /* displayChange */);
+ app.mTransitionController.collectExistenceChange(app.getTask());
+ mDisplayContent.setFixedRotationLaunchingAppUnchecked(app);
+ final AsyncRotationController asyncRotationController =
+ mDisplayContent.getAsyncRotationController();
+ assertNotNull(asyncRotationController);
+ assertTrue(asyncRotationController.shouldFreezeInsetsPosition(statusBar));
+ assertTrue(app.getTask().inTransition());
+
+ player.start();
+ player.finish();
+ app.getTask().clearSyncState();
+
+ // The open transition is finished. Continue to play seamless display change transition,
+ // so the previous async rotation controller should still exist.
+ mDisplayContent.getDisplayRotation().setRotation(mDisplayContent.getRotation() + 1);
+ mDisplayContent.setLastHasContent();
+ mDisplayContent.requestChangeTransitionIfNeeded(1 /* changes */, null /* displayChange */);
+ assertTrue(mDisplayContent.hasTopFixedRotationLaunchingApp());
+ assertNotNull(mDisplayContent.getAsyncRotationController());
+
+ statusBar.setOrientationChanging(true);
+ player.startTransition();
+ // Non-app windows should not be collected.
+ assertFalse(statusBar.mToken.inTransition());
+
+ onRotationTransactionReady(player, mWm.mTransactionFactory.get()).onTransactionCommitted();
+ assertEquals(ROTATION_ANIMATION_SEAMLESS, player.mLastReady.getChange(
+ mDisplayContent.mRemoteToken.toWindowContainerToken()).getRotationAnimation());
+ player.finish();
+
+ // The controller should be cleared if the target windows are drawn.
+ statusBar.finishDrawing(mWm.mTransactionFactory.get());
+ statusBar.setOrientationChanging(false);
+ assertNull(mDisplayContent.getAsyncRotationController());
+ }
+
+ @Test
+ public void testDeferRotationForTransientLaunch() {
+ final TestTransitionPlayer player = registerTestTransitionPlayer();
+ assumeFalse(mDisplayContent.mTransitionController.useShellTransitionsRotation());
+ final ActivityRecord app = new ActivityBuilder(mAtm).setCreateTask(true).build();
+ final ActivityRecord home = new ActivityBuilder(mAtm)
+ .setTask(mDisplayContent.getDefaultTaskDisplayArea().getRootHomeTask())
+ .setScreenOrientation(SCREEN_ORIENTATION_NOSENSOR).setVisible(false).build();
+ final Transition transition = home.mTransitionController.createTransition(TRANSIT_OPEN);
+ final int prevRotation = mDisplayContent.getRotation();
+ transition.setTransientLaunch(home, null /* restoreBelow */);
+ home.mTransitionController.requestStartTransition(transition, home.getTask(),
+ null /* remoteTransition */, null /* displayChange */);
+ transition.collectExistenceChange(home);
+ home.mVisibleRequested = true;
+ mDisplayContent.setFixedRotationLaunchingAppUnchecked(home);
+ doReturn(true).when(home).hasFixedRotationTransform(any());
+ player.startTransition();
+ player.onTransactionReady(mDisplayContent.getSyncTransaction());
+
+ final DisplayRotation displayRotation = mDisplayContent.getDisplayRotation();
+ spyOn(displayRotation);
+ doReturn(true).when(displayRotation).isWaitingForRemoteRotation();
+ doReturn(prevRotation + 1).when(displayRotation).rotationForOrientation(
+ anyInt() /* orientation */, anyInt() /* lastRotation */);
+ // Rotation update is skipped while the recents animation is running.
+ assertFalse(mDisplayContent.updateRotationUnchecked());
+ assertEquals(SCREEN_ORIENTATION_NOSENSOR, displayRotation.getLastOrientation());
+ // Return to the app without fixed orientation from recents.
+ app.moveFocusableActivityToTop("test");
+ player.finish();
+ // The display should be updated to the changed orientation after the animation is finish.
+ assertNotEquals(mDisplayContent.getRotation(), prevRotation);
+ }
+
@Test
public void testIntermediateVisibility() {
final TaskSnapshotController snapshotController = mock(TaskSnapshotController.class);
diff --git a/services/tests/wmtests/src/com/android/server/wm/WindowLayoutTests.java b/services/tests/wmtests/src/com/android/server/wm/WindowLayoutTests.java
index 338555e..7d2e9bf 100644
--- a/services/tests/wmtests/src/com/android/server/wm/WindowLayoutTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/WindowLayoutTests.java
@@ -30,6 +30,7 @@
import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER;
import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_INSET_PARENT_FRAME_BY_IME;
+import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_LAYOUT_SIZE_EXTENDED_BY_CUTOUT;
import static org.junit.Assert.assertEquals;
@@ -330,6 +331,23 @@
}
@Test
+ public void layoutExtendedToDisplayCutout() {
+ addDisplayCutout();
+ final int height = DISPLAY_HEIGHT / 2;
+ mRequestedHeight = UNSPECIFIED_LENGTH;
+ mAttrs.height = height;
+ mAttrs.gravity = Gravity.TOP;
+ mAttrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
+ mAttrs.setFitInsetsTypes(0);
+ mAttrs.privateFlags |= PRIVATE_FLAG_LAYOUT_SIZE_EXTENDED_BY_CUTOUT;
+ computeFrames();
+
+ assertRect(0, 0, DISPLAY_WIDTH, DISPLAY_HEIGHT, mDisplayFrame);
+ assertRect(0, 0, DISPLAY_WIDTH, DISPLAY_HEIGHT, mParentFrame);
+ assertRect(0, 0, DISPLAY_WIDTH, height + DISPLAY_CUTOUT_HEIGHT, mFrame);
+ }
+
+ @Test
public void layoutInDisplayCutoutModeDefaultWithInvisibleSystemBars() {
addDisplayCutout();
mState.getSource(ITYPE_STATUS_BAR).setVisible(false);
diff --git a/services/tests/wmtests/src/com/android/server/wm/WindowOrganizerTests.java b/services/tests/wmtests/src/com/android/server/wm/WindowOrganizerTests.java
index 4d5fb6d..25d7334 100644
--- a/services/tests/wmtests/src/com/android/server/wm/WindowOrganizerTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/WindowOrganizerTests.java
@@ -30,6 +30,7 @@
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
import static android.content.res.Configuration.SCREEN_HEIGHT_DP_UNDEFINED;
import static android.content.res.Configuration.SCREEN_WIDTH_DP_UNDEFINED;
+import static android.view.InsetsState.ITYPE_LOCAL_NAVIGATION_BAR_1;
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doNothing;
@@ -610,6 +611,50 @@
assertEquals(ACTIVITY_TYPE_UNDEFINED, info1.topActivityType);
}
+ @Test
+ public void testAddRectInsetsProvider() {
+ final Task rootTask = createTask(mDisplayContent);
+
+ final Task navigationBarInsetsReceiverTask = createTaskInRootTask(rootTask, 0);
+ navigationBarInsetsReceiverTask.getConfiguration().windowConfiguration.setBounds(new Rect(
+ 0, 200, 1080, 700));
+
+ final Rect navigationBarInsetsProviderRect = new Rect(0, 0, 1080, 200);
+
+ final WindowContainerTransaction wct = new WindowContainerTransaction();
+ wct.addRectInsetsProvider(navigationBarInsetsReceiverTask.mRemoteToken
+ .toWindowContainerToken(), navigationBarInsetsProviderRect,
+ new int[]{ITYPE_LOCAL_NAVIGATION_BAR_1});
+ mWm.mAtmService.mWindowOrganizerController.applyTransaction(wct);
+
+ assertThat(navigationBarInsetsReceiverTask.mLocalInsetsSourceProviders
+ .valueAt(0).getSource().getType()).isEqualTo(ITYPE_LOCAL_NAVIGATION_BAR_1);
+ }
+
+ @Test
+ public void testRemoveInsetsProvider() {
+ final Task rootTask = createTask(mDisplayContent);
+
+ final Task navigationBarInsetsReceiverTask = createTaskInRootTask(rootTask, 0);
+ navigationBarInsetsReceiverTask.getConfiguration().windowConfiguration.setBounds(new Rect(
+ 0, 200, 1080, 700));
+
+ final Rect navigationBarInsetsProviderRect = new Rect(0, 0, 1080, 200);
+
+ final WindowContainerTransaction wct = new WindowContainerTransaction();
+ wct.addRectInsetsProvider(navigationBarInsetsReceiverTask.mRemoteToken
+ .toWindowContainerToken(), navigationBarInsetsProviderRect,
+ new int[]{ITYPE_LOCAL_NAVIGATION_BAR_1});
+ mWm.mAtmService.mWindowOrganizerController.applyTransaction(wct);
+
+ final WindowContainerTransaction wct2 = new WindowContainerTransaction();
+ wct2.removeInsetsProvider(navigationBarInsetsReceiverTask.mRemoteToken
+ .toWindowContainerToken(), new int[]{ITYPE_LOCAL_NAVIGATION_BAR_1});
+ mWm.mAtmService.mWindowOrganizerController.applyTransaction(wct2);
+
+ assertThat(navigationBarInsetsReceiverTask.mLocalInsetsSourceProviders.size()).isEqualTo(0);
+ }
+
@UseTestDisplay
@Test
public void testTaskInfoCallback() {
diff --git a/services/usb/java/com/android/server/usb/UsbDeviceManager.java b/services/usb/java/com/android/server/usb/UsbDeviceManager.java
index 7f70301..1999cfc 100644
--- a/services/usb/java/com/android/server/usb/UsbDeviceManager.java
+++ b/services/usb/java/com/android/server/usb/UsbDeviceManager.java
@@ -2187,7 +2187,7 @@
* @param uid Uid of the caller
*/
public ParcelFileDescriptor openAccessory(UsbAccessory accessory,
- UsbUserPermissionManager permissions, int uid) {
+ UsbUserPermissionManager permissions, int pid, int uid) {
UsbAccessory currentAccessory = mHandler.getCurrentAccessory();
if (currentAccessory == null) {
throw new IllegalArgumentException("no accessory attached");
@@ -2198,7 +2198,7 @@
+ currentAccessory;
throw new IllegalArgumentException(error);
}
- permissions.checkPermission(accessory, uid);
+ permissions.checkPermission(accessory, pid, uid);
return nativeOpenAccessory();
}
diff --git a/services/usb/java/com/android/server/usb/UsbSerialReader.java b/services/usb/java/com/android/server/usb/UsbSerialReader.java
index f241e65..9dda0e7 100644
--- a/services/usb/java/com/android/server/usb/UsbSerialReader.java
+++ b/services/usb/java/com/android/server/usb/UsbSerialReader.java
@@ -98,7 +98,7 @@
.checkPermission((UsbDevice) mDevice, packageName, pid, uid);
} else {
mPermissionManager.getPermissionsForUser(userId)
- .checkPermission((UsbAccessory) mDevice, uid);
+ .checkPermission((UsbAccessory) mDevice, pid, uid);
}
}
}
diff --git a/services/usb/java/com/android/server/usb/UsbService.java b/services/usb/java/com/android/server/usb/UsbService.java
index c0ecf58..e06ab02 100644
--- a/services/usb/java/com/android/server/usb/UsbService.java
+++ b/services/usb/java/com/android/server/usb/UsbService.java
@@ -321,6 +321,7 @@
public ParcelFileDescriptor openAccessory(UsbAccessory accessory) {
if (mDeviceManager != null) {
int uid = Binder.getCallingUid();
+ int pid = Binder.getCallingPid();
int user = UserHandle.getUserId(uid);
final long ident = clearCallingIdentity();
@@ -328,7 +329,7 @@
synchronized (mLock) {
if (mUserManager.isSameProfileGroup(user, mCurrentUserId)) {
return mDeviceManager.openAccessory(accessory, getPermissionsForUser(user),
- uid);
+ pid, uid);
} else {
Slog.w(TAG, "Cannot open " + accessory + " for user " + user
+ " as user is not active.");
@@ -505,11 +506,12 @@
@Override
public boolean hasAccessoryPermission(UsbAccessory accessory) {
final int uid = Binder.getCallingUid();
+ final int pid = Binder.getCallingPid();
final int userId = UserHandle.getUserId(uid);
final long token = Binder.clearCallingIdentity();
try {
- return getPermissionsForUser(userId).hasPermission(accessory, uid);
+ return getPermissionsForUser(userId).hasPermission(accessory, pid, uid);
} finally {
Binder.restoreCallingIdentity(token);
}
@@ -533,11 +535,12 @@
public void requestAccessoryPermission(
UsbAccessory accessory, String packageName, PendingIntent pi) {
final int uid = Binder.getCallingUid();
+ final int pid = Binder.getCallingPid();
final int userId = UserHandle.getUserId(uid);
final long token = Binder.clearCallingIdentity();
try {
- getPermissionsForUser(userId).requestPermission(accessory, packageName, pi, uid);
+ getPermissionsForUser(userId).requestPermission(accessory, packageName, pi, pid, uid);
} finally {
Binder.restoreCallingIdentity(token);
}
diff --git a/services/usb/java/com/android/server/usb/UsbUserPermissionManager.java b/services/usb/java/com/android/server/usb/UsbUserPermissionManager.java
index 286cff9..dd5f153 100644
--- a/services/usb/java/com/android/server/usb/UsbUserPermissionManager.java
+++ b/services/usb/java/com/android/server/usb/UsbUserPermissionManager.java
@@ -246,9 +246,13 @@
* @param uid to check permission for
* @return {@code true} if caller has permssion
*/
- boolean hasPermission(@NonNull UsbAccessory accessory, int uid) {
+ boolean hasPermission(@NonNull UsbAccessory accessory, int pid, int uid) {
synchronized (mLock) {
- if (uid == Process.SYSTEM_UID || mDisablePermissionDialogs) {
+ if (uid == Process.SYSTEM_UID
+ || mDisablePermissionDialogs
+ || mContext.checkPermission(
+ android.Manifest.permission.MANAGE_USB, pid, uid)
+ == android.content.pm.PackageManager.PERMISSION_GRANTED) {
return true;
}
AccessoryFilter filter = new AccessoryFilter(accessory);
@@ -675,8 +679,8 @@
}
}
- public void checkPermission(UsbAccessory accessory, int uid) {
- if (!hasPermission(accessory, uid)) {
+ public void checkPermission(UsbAccessory accessory, int pid, int uid) {
+ if (!hasPermission(accessory, pid, uid)) {
throw new SecurityException("User has not given " + uid + " permission to accessory "
+ accessory);
}
@@ -745,9 +749,9 @@
}
public void requestPermission(UsbAccessory accessory, String packageName, PendingIntent pi,
- int uid) {
+ int pid, int uid) {
// respond immediately if permission has already been granted
- if (hasPermission(accessory, uid)) {
+ if (hasPermission(accessory, pid, uid)) {
Intent intent = new Intent();
intent.putExtra(UsbManager.EXTRA_ACCESSORY, accessory);
intent.putExtra(UsbManager.EXTRA_PERMISSION_GRANTED, true);
diff --git a/telecomm/java/android/telecom/TelecomManager.java b/telecomm/java/android/telecom/TelecomManager.java
index f43e5aa..df114db 100644
--- a/telecomm/java/android/telecom/TelecomManager.java
+++ b/telecomm/java/android/telecom/TelecomManager.java
@@ -1292,31 +1292,22 @@
}
/**
- * Returns a list of {@link PhoneAccountHandle}s for self-managed {@link ConnectionService}s.
+ * Returns a list of {@link PhoneAccountHandle}s for all self-managed
+ * {@link ConnectionService}s owned by the calling {@link UserHandle}.
* <p>
* Self-Managed {@link ConnectionService}s have a {@link PhoneAccount} with
* {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.
* <p>
* Requires permission {@link android.Manifest.permission#READ_PHONE_STATE}, or that the caller
- * is the default dialer app to get all phone account handles.
- * <P>
- * If the caller doesn't meet any of the above requirements and has {@link
- * android.Manifest.permission#MANAGE_OWN_CALLS}, the caller can get only the phone account
- * handles they have registered.
+ * is the default dialer app.
* <p>
- * A {@link SecurityException} will be thrown if the caller is not the default dialer
- * or the caller does not have at least one of the following permissions:
- * {@link android.Manifest.permission#READ_PHONE_STATE} permission,
- * {@link android.Manifest.permission#MANAGE_OWN_CALLS} permission
+ * A {@link SecurityException} will be thrown if a called is not the default dialer, or lacks
+ * the {@link android.Manifest.permission#READ_PHONE_STATE} permission.
*
* @return A list of {@code PhoneAccountHandle} objects.
*/
- @RequiresPermission(anyOf = {
- READ_PRIVILEGED_PHONE_STATE,
- android.Manifest.permission.READ_PHONE_STATE,
- android.Manifest.permission.MANAGE_OWN_CALLS
- })
- public List<PhoneAccountHandle> getSelfManagedPhoneAccounts() {
+ @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
+ public @NonNull List<PhoneAccountHandle> getSelfManagedPhoneAccounts() {
ITelecomService service = getTelecomService();
if (service != null) {
try {
@@ -1330,6 +1321,34 @@
}
/**
+ * Returns a list of {@link PhoneAccountHandle}s owned by the calling self-managed
+ * {@link ConnectionService}.
+ * <p>
+ * Self-Managed {@link ConnectionService}s have a {@link PhoneAccount} with
+ * {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.
+ * <p>
+ * Requires permission {@link android.Manifest.permission#MANAGE_OWN_CALLS}
+ * <p>
+ * A {@link SecurityException} will be thrown if a caller lacks the
+ * {@link android.Manifest.permission#MANAGE_OWN_CALLS} permission.
+ *
+ * @return A list of {@code PhoneAccountHandle} objects.
+ */
+ @RequiresPermission(Manifest.permission.MANAGE_OWN_CALLS)
+ public @NonNull List<PhoneAccountHandle> getOwnSelfManagedPhoneAccounts() {
+ ITelecomService service = getTelecomService();
+ if (service != null) {
+ try {
+ return service.getOwnSelfManagedPhoneAccounts(mContext.getOpPackageName(),
+ mContext.getAttributionTag());
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
+ }
+ throw new IllegalStateException("Telecom is not available");
+ }
+
+ /**
* Returns a list of {@link PhoneAccountHandle}s including those which have not been enabled
* by the user.
*
diff --git a/telecomm/java/com/android/internal/telecom/ITelecomService.aidl b/telecomm/java/com/android/internal/telecom/ITelecomService.aidl
index b9936ce..9999c89 100644
--- a/telecomm/java/com/android/internal/telecom/ITelecomService.aidl
+++ b/telecomm/java/com/android/internal/telecom/ITelecomService.aidl
@@ -66,6 +66,12 @@
String callingFeatureId);
/**
+ * @see TelecomServiceImpl#getOwnSelfManagedPhoneAccounts
+ */
+ List<PhoneAccountHandle> getOwnSelfManagedPhoneAccounts(String callingPackage,
+ String callingFeatureId);
+
+ /**
* @see TelecomManager#getPhoneAccountsSupportingScheme
*/
List<PhoneAccountHandle> getPhoneAccountsSupportingScheme(in String uriScheme,
diff --git a/telephony/java/android/telephony/CarrierConfigManager.java b/telephony/java/android/telephony/CarrierConfigManager.java
index adb51c4..837cf8b 100644
--- a/telephony/java/android/telephony/CarrierConfigManager.java
+++ b/telephony/java/android/telephony/CarrierConfigManager.java
@@ -3850,30 +3850,42 @@
public static final String KEY_OPPORTUNISTIC_ESIM_DOWNLOAD_VIA_WIFI_ONLY_BOOL =
"opportunistic_esim_download_via_wifi_only_bool";
- /**
- * Controls RSRP threshold at which OpportunisticNetworkService will decide whether
+/**
+ * Controls RSRP threshold, in dBm, at which OpportunisticNetworkService will decide whether
* the opportunistic network is good enough for internet data.
+ *
+ * <p>The value of {@link CellSignalStrengthLte#getRsrp()} will be compared with this
+ * threshold.
*/
public static final String KEY_OPPORTUNISTIC_NETWORK_ENTRY_THRESHOLD_RSRP_INT =
"opportunistic_network_entry_threshold_rsrp_int";
/**
- * Controls RSSNR threshold at which OpportunisticNetworkService will decide whether
- * the opportunistic network is good enough for internet data.
+ * Controls RSSNR threshold, in dB, at which OpportunisticNetworkService will
+ * decide whether the opportunistic network is good enough for internet data.
+ *
+ * <p>The value of {@link CellSignalStrengthLte#getRssnr()} will be compared with this
+ * threshold.
*/
public static final String KEY_OPPORTUNISTIC_NETWORK_ENTRY_THRESHOLD_RSSNR_INT =
"opportunistic_network_entry_threshold_rssnr_int";
/**
- * Controls RSRP threshold below which OpportunisticNetworkService will decide whether
+ * Controls RSRP threshold, in dBm, below which OpportunisticNetworkService will decide whether
* the opportunistic network available is not good enough for internet data.
+ *
+ * <p>The value of {@link CellSignalStrengthLte#getRsrp()} will be compared with this
+ * threshold.
*/
public static final String KEY_OPPORTUNISTIC_NETWORK_EXIT_THRESHOLD_RSRP_INT =
"opportunistic_network_exit_threshold_rsrp_int";
/**
- * Controls RSSNR threshold below which OpportunisticNetworkService will decide whether
- * the opportunistic network available is not good enough for internet data.
+ * Controls RSSNR threshold, in dB, below which OpportunisticNetworkService will
+ * decide whether the opportunistic network available is not good enough for internet data.
+ *
+ * <p>The value of {@link CellSignalStrengthLte#getRssnr()} will be compared with this
+ * threshold.
*/
public static final String KEY_OPPORTUNISTIC_NETWORK_EXIT_THRESHOLD_RSSNR_INT =
"opportunistic_network_exit_threshold_rssnr_int";
@@ -3971,7 +3983,7 @@
* good enough for internet data. Note other factors may be considered for the final
* decision.
*
- * <p>The value of {@link CellSignalStrengthNr#getSsRsrp} will be compared with this
+ * <p>The value of {@link CellSignalStrengthNr#getSsRsrp()} will be compared with this
* threshold.
*
* @hide
@@ -3998,7 +4010,7 @@
* good enough for internet data. Note other factors may be considered for the final
* decision.
*
- * <p>The value of {@link CellSignalStrengthNr#getSsRsrq} will be compared with this
+ * <p>The value of {@link CellSignalStrengthNr#getSsRsrq()} will be compared with this
* threshold.
*
* @hide
@@ -4025,6 +4037,9 @@
* be considered good enough for internet data. Note other factors may be considered
* for the final decision.
*
+ * <p>The value of {@link CellSignalStrengthNr#getSsRsrp()} will be compared with this
+ * threshold.
+ *
* @hide
*/
public static final String KEY_EXIT_THRESHOLD_SS_RSRP_INT =
@@ -4048,6 +4063,9 @@
* be considered good enough for internet data. Note other factors may be considered
* for the final decision.
*
+ * <p>The value of {@link CellSignalStrengthNr#getSsRsrq()} will be compared with this
+ * threshold.
+ *
* @hide
*/
public static final String KEY_EXIT_THRESHOLD_SS_RSRQ_DOUBLE =
@@ -8995,9 +9013,9 @@
/* Default value is minimum RSRP level needed for SIGNAL_STRENGTH_MODERATE */
sDefaults.putInt(KEY_OPPORTUNISTIC_NETWORK_EXIT_THRESHOLD_RSRP_INT, -118);
/* Default value is minimum RSSNR level needed for SIGNAL_STRENGTH_GOOD */
- sDefaults.putInt(KEY_OPPORTUNISTIC_NETWORK_ENTRY_THRESHOLD_RSSNR_INT, 45);
+ sDefaults.putInt(KEY_OPPORTUNISTIC_NETWORK_ENTRY_THRESHOLD_RSSNR_INT, 5);
/* Default value is minimum RSSNR level needed for SIGNAL_STRENGTH_MODERATE */
- sDefaults.putInt(KEY_OPPORTUNISTIC_NETWORK_EXIT_THRESHOLD_RSSNR_INT, 10);
+ sDefaults.putInt(KEY_OPPORTUNISTIC_NETWORK_EXIT_THRESHOLD_RSSNR_INT, 1);
/* Default value is 1024 kbps */
sDefaults.putInt(KEY_OPPORTUNISTIC_NETWORK_ENTRY_THRESHOLD_BANDWIDTH_INT, 1024);
/* Default value is 10 seconds */
diff --git a/telephony/java/android/telephony/CellSignalStrengthLte.java b/telephony/java/android/telephony/CellSignalStrengthLte.java
index 947dc01..5e90261 100644
--- a/telephony/java/android/telephony/CellSignalStrengthLte.java
+++ b/telephony/java/android/telephony/CellSignalStrengthLte.java
@@ -125,13 +125,13 @@
/**
* Construct a cell signal strength
*
- * @param rssi in dBm [-113,-51], UNKNOWN
- * @param rsrp in dBm [-140,-43], UNKNOWN
- * @param rsrq in dB [-34, 3], UNKNOWN
- * @param rssnr in dB [-20, +30], UNKNOWN
- * @param cqiTableIndex [1, 6], UNKNOWN
- * @param cqi [0, 15], UNKNOWN
- * @param timingAdvance [0, 1282], UNKNOWN
+ * @param rssi in dBm [-113,-51], {@link CellInfo#UNAVAILABLE}
+ * @param rsrp in dBm [-140,-43], {@link CellInfo#UNAVAILABLE}
+ * @param rsrq in dB [-34, 3], {@link CellInfo#UNAVAILABLE}
+ * @param rssnr in dB [-20, +30], {@link CellInfo#UNAVAILABLE}
+ * @param cqiTableIndex [1, 6], {@link CellInfo#UNAVAILABLE}
+ * @param cqi [0, 15], {@link CellInfo#UNAVAILABLE}
+ * @param timingAdvance [0, 1282], {@link CellInfo#UNAVAILABLE}
*
*/
/** @hide */
@@ -151,12 +151,12 @@
/**
* Construct a cell signal strength
*
- * @param rssi in dBm [-113,-51], UNKNOWN
- * @param rsrp in dBm [-140,-43], UNKNOWN
- * @param rsrq in dB [-34, 3], UNKNOWN
- * @param rssnr in dB [-20, +30], UNKNOWN
- * @param cqi [0, 15], UNKNOWN
- * @param timingAdvance [0, 1282], UNKNOWN
+ * @param rssi in dBm [-113,-51], {@link CellInfo#UNAVAILABLE}
+ * @param rsrp in dBm [-140,-43], {@link CellInfo#UNAVAILABLE}
+ * @param rsrq in dB [-34, 3], {@link CellInfo#UNAVAILABLE}
+ * @param rssnr in dB [-20, +30], {@link CellInfo#UNAVAILABLE}
+ * @param cqi [0, 15], {@link CellInfo#UNAVAILABLE}
+ * @param timingAdvance [0, 1282], {@link CellInfo#UNAVAILABLE}
*
*/
/** @hide */
@@ -403,10 +403,11 @@
}
/**
- * Get reference signal signal-to-noise ratio
+ * Get reference signal signal-to-noise ratio in dB
+ * Range: -20 dB to +30 dB.
*
* @return the RSSNR if available or
- * {@link android.telephony.CellInfo#UNAVAILABLE UNAVAILABLE} if unavailable.
+ * {@link android.telephony.CellInfo#UNAVAILABLE} if unavailable.
*/
public int getRssnr() {
return mRssnr;
@@ -414,8 +415,10 @@
/**
* Get reference signal received power in dBm
+ * Range: -140 dBm to -43 dBm.
*
- * @return the RSRP of the measured cell.
+ * @return the RSRP of the measured cell or {@link CellInfo#UNAVAILABLE} if
+ * unavailable.
*/
public int getRsrp() {
return mRsrp;
diff --git a/telephony/java/android/telephony/data/ApnSetting.java b/telephony/java/android/telephony/data/ApnSetting.java
index 8e10f6b..fc94ebf 100644
--- a/telephony/java/android/telephony/data/ApnSetting.java
+++ b/telephony/java/android/telephony/data/ApnSetting.java
@@ -369,6 +369,10 @@
public @interface AuthType {}
// Possible values for protocol which is defined in TS 27.007 section 10.1.1.
+ /** Unknown protocol.
+ * @hide
+ */
+ public static final int PROTOCOL_UNKNOWN = -1;
/** Internet protocol. */
public static final int PROTOCOL_IP = 0;
/** Internet protocol, version 6. */
diff --git a/tests/TrustTests/OWNERS b/tests/TrustTests/OWNERS
new file mode 100644
index 0000000..e2c6ce1
--- /dev/null
+++ b/tests/TrustTests/OWNERS
@@ -0,0 +1 @@
+include /core/java/android/service/trust/OWNERS