Merge changes I197e8b52,I1fde6850 into udc-qpr-dev am: 6552d2f34a
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/24039362 Change-Id: I13e6fb7d4b7bdd2391502add63b2d670d8abe8d1 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -24,14 +24,10 @@ import android.os.Binder;
|
|||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.util.Slog;
|
import android.util.Slog;
|
||||||
|
|
||||||
import com.android.internal.infra.AndroidFuture;
|
|
||||||
import com.android.internal.util.CollectionUtils;
|
import com.android.internal.util.CollectionUtils;
|
||||||
import com.android.server.FgThread;
|
import com.android.server.FgThread;
|
||||||
|
|
||||||
import java.util.concurrent.ExecutionException;
|
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import java.util.concurrent.TimeoutException;
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
@@ -70,27 +66,19 @@ public class DefaultAppProvider {
|
|||||||
* Set the package name of the default browser.
|
* Set the package name of the default browser.
|
||||||
*
|
*
|
||||||
* @param packageName package name of the default browser, or {@code null} to unset
|
* @param packageName package name of the default browser, or {@code null} to unset
|
||||||
* @param async whether the operation should be asynchronous
|
|
||||||
* @param userId the user ID
|
* @param userId the user ID
|
||||||
* @return whether the default browser was successfully set.
|
|
||||||
*/
|
*/
|
||||||
public boolean setDefaultBrowser(@Nullable String packageName, boolean async,
|
public void setDefaultBrowser(@Nullable String packageName, @UserIdInt int userId) {
|
||||||
@UserIdInt int userId) {
|
|
||||||
if (userId == UserHandle.USER_ALL) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
final RoleManager roleManager = mRoleManagerSupplier.get();
|
final RoleManager roleManager = mRoleManagerSupplier.get();
|
||||||
if (roleManager == null) {
|
if (roleManager == null) {
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
final UserHandle user = UserHandle.of(userId);
|
final UserHandle user = UserHandle.of(userId);
|
||||||
final Executor executor = FgThread.getExecutor();
|
final Executor executor = FgThread.getExecutor();
|
||||||
final AndroidFuture<Void> future = new AndroidFuture<>();
|
|
||||||
final Consumer<Boolean> callback = successful -> {
|
final Consumer<Boolean> callback = successful -> {
|
||||||
if (successful) {
|
if (!successful) {
|
||||||
future.complete(null);
|
Slog.e(PackageManagerService.TAG, "Failed to set default browser to "
|
||||||
} else {
|
+ packageName);
|
||||||
future.completeExceptionally(new RuntimeException());
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
final long identity = Binder.clearCallingIdentity();
|
final long identity = Binder.clearCallingIdentity();
|
||||||
@@ -102,19 +90,9 @@ public class DefaultAppProvider {
|
|||||||
roleManager.clearRoleHoldersAsUser(RoleManager.ROLE_BROWSER, 0, user, executor,
|
roleManager.clearRoleHoldersAsUser(RoleManager.ROLE_BROWSER, 0, user, executor,
|
||||||
callback);
|
callback);
|
||||||
}
|
}
|
||||||
if (!async) {
|
|
||||||
try {
|
|
||||||
future.get(5, TimeUnit.SECONDS);
|
|
||||||
} catch (InterruptedException | ExecutionException | TimeoutException e) {
|
|
||||||
Slog.e(PackageManagerService.TAG, "Exception while setting default browser: "
|
|
||||||
+ packageName, e);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} finally {
|
} finally {
|
||||||
Binder.restoreCallingIdentity(identity);
|
Binder.restoreCallingIdentity(identity);
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -3535,6 +3535,18 @@ public class PackageManagerService implements PackageSender, TestUtilityService
|
|||||||
// within these users.
|
// within these users.
|
||||||
mPermissionManager.restoreDelayedRuntimePermissions(packageName, userId);
|
mPermissionManager.restoreDelayedRuntimePermissions(packageName, userId);
|
||||||
|
|
||||||
|
// Restore default browser setting if it is now installed.
|
||||||
|
String defaultBrowser;
|
||||||
|
synchronized (mLock) {
|
||||||
|
defaultBrowser = mSettings.getPendingDefaultBrowserLPr(userId);
|
||||||
|
}
|
||||||
|
if (Objects.equals(packageName, defaultBrowser)) {
|
||||||
|
mDefaultAppProvider.setDefaultBrowser(packageName, userId);
|
||||||
|
synchronized (mLock) {
|
||||||
|
mSettings.removePendingDefaultBrowserLPw(userId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Persistent preferred activity might have came into effect due to this
|
// Persistent preferred activity might have came into effect due to this
|
||||||
// install.
|
// install.
|
||||||
mPreferredActivityHelper.updateDefaultHomeNotLocked(snapshotComputer(), userId);
|
mPreferredActivityHelper.updateDefaultHomeNotLocked(snapshotComputer(), userId);
|
||||||
@@ -6732,7 +6744,7 @@ public class PackageManagerService implements PackageSender, TestUtilityService
|
|||||||
@Override
|
@Override
|
||||||
public String removeLegacyDefaultBrowserPackageName(int userId) {
|
public String removeLegacyDefaultBrowserPackageName(int userId) {
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
return mSettings.removeDefaultBrowserPackageNameLPw(userId);
|
return mSettings.removePendingDefaultBrowserLPw(userId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -7574,8 +7586,8 @@ public class PackageManagerService implements PackageSender, TestUtilityService
|
|||||||
return mDefaultAppProvider.getDefaultBrowser(userId);
|
return mDefaultAppProvider.getDefaultBrowser(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setDefaultBrowser(@Nullable String packageName, boolean async, @UserIdInt int userId) {
|
void setDefaultBrowser(@Nullable String packageName, @UserIdInt int userId) {
|
||||||
mDefaultAppProvider.setDefaultBrowser(packageName, async, userId);
|
mDefaultAppProvider.setDefaultBrowser(packageName, userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
PackageUsage getPackageUsage() {
|
PackageUsage getPackageUsage() {
|
||||||
|
|||||||
@@ -585,7 +585,17 @@ final class PreferredActivityHelper {
|
|||||||
(parser1, userId1) -> {
|
(parser1, userId1) -> {
|
||||||
final String defaultBrowser = Settings.readDefaultApps(parser1);
|
final String defaultBrowser = Settings.readDefaultApps(parser1);
|
||||||
if (defaultBrowser != null) {
|
if (defaultBrowser != null) {
|
||||||
mPm.setDefaultBrowser(defaultBrowser, false, userId1);
|
final PackageStateInternal packageState = mPm.snapshotComputer()
|
||||||
|
.getPackageStateInternal(defaultBrowser);
|
||||||
|
if (packageState != null
|
||||||
|
&& packageState.getUserStateOrDefault(userId1).isInstalled()) {
|
||||||
|
mPm.setDefaultBrowser(defaultBrowser, userId1);
|
||||||
|
} else {
|
||||||
|
synchronized (mPm.mLock) {
|
||||||
|
mPm.mSettings.setPendingDefaultBrowserLPw(defaultBrowser,
|
||||||
|
userId1);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
@@ -517,9 +517,11 @@ public final class Settings implements Watchable, Snappable, ResilientAtomicFile
|
|||||||
private final WatchedArrayMap<String, String> mRenamedPackages =
|
private final WatchedArrayMap<String, String> mRenamedPackages =
|
||||||
new WatchedArrayMap<String, String>();
|
new WatchedArrayMap<String, String>();
|
||||||
|
|
||||||
// For every user, it is used to find the package name of the default Browser App.
|
// For every user, it is used to find the package name of the default browser app pending to be
|
||||||
|
// applied, either on first boot after upgrade, or after backup & restore but before app is
|
||||||
|
// installed.
|
||||||
@Watched
|
@Watched
|
||||||
final WatchedSparseArray<String> mDefaultBrowserApp = new WatchedSparseArray<String>();
|
final WatchedSparseArray<String> mPendingDefaultBrowser = new WatchedSparseArray<>();
|
||||||
|
|
||||||
// TODO(b/161161364): This seems unused, and is probably not relevant in the new API, but should
|
// TODO(b/161161364): This seems unused, and is probably not relevant in the new API, but should
|
||||||
// verify.
|
// verify.
|
||||||
@@ -592,7 +594,7 @@ public final class Settings implements Watchable, Snappable, ResilientAtomicFile
|
|||||||
mAppIds.registerObserver(mObserver);
|
mAppIds.registerObserver(mObserver);
|
||||||
mRenamedPackages.registerObserver(mObserver);
|
mRenamedPackages.registerObserver(mObserver);
|
||||||
mNextAppLinkGeneration.registerObserver(mObserver);
|
mNextAppLinkGeneration.registerObserver(mObserver);
|
||||||
mDefaultBrowserApp.registerObserver(mObserver);
|
mPendingDefaultBrowser.registerObserver(mObserver);
|
||||||
mPendingPackages.registerObserver(mObserver);
|
mPendingPackages.registerObserver(mObserver);
|
||||||
mPastSignatures.registerObserver(mObserver);
|
mPastSignatures.registerObserver(mObserver);
|
||||||
mKeySetRefs.registerObserver(mObserver);
|
mKeySetRefs.registerObserver(mObserver);
|
||||||
@@ -787,7 +789,7 @@ public final class Settings implements Watchable, Snappable, ResilientAtomicFile
|
|||||||
|
|
||||||
mRenamedPackages.snapshot(r.mRenamedPackages);
|
mRenamedPackages.snapshot(r.mRenamedPackages);
|
||||||
mNextAppLinkGeneration.snapshot(r.mNextAppLinkGeneration);
|
mNextAppLinkGeneration.snapshot(r.mNextAppLinkGeneration);
|
||||||
mDefaultBrowserApp.snapshot(r.mDefaultBrowserApp);
|
mPendingDefaultBrowser.snapshot(r.mPendingDefaultBrowser);
|
||||||
// mReadMessages
|
// mReadMessages
|
||||||
mPendingPackages = r.mPendingPackagesSnapshot.snapshot();
|
mPendingPackages = r.mPendingPackagesSnapshot.snapshot();
|
||||||
mPendingPackagesSnapshot = new SnapshotCache.Sealed<>();
|
mPendingPackagesSnapshot = new SnapshotCache.Sealed<>();
|
||||||
@@ -1504,8 +1506,16 @@ public final class Settings implements Watchable, Snappable, ResilientAtomicFile
|
|||||||
return cpir;
|
return cpir;
|
||||||
}
|
}
|
||||||
|
|
||||||
String removeDefaultBrowserPackageNameLPw(int userId) {
|
String getPendingDefaultBrowserLPr(int userId) {
|
||||||
return (userId == UserHandle.USER_ALL) ? null : mDefaultBrowserApp.removeReturnOld(userId);
|
return mPendingDefaultBrowser.get(userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setPendingDefaultBrowserLPw(String defaultBrowser, int userId) {
|
||||||
|
mPendingDefaultBrowser.put(userId, defaultBrowser);
|
||||||
|
}
|
||||||
|
|
||||||
|
String removePendingDefaultBrowserLPw(int userId) {
|
||||||
|
return mPendingDefaultBrowser.removeReturnOld(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private File getUserSystemDirectory(int userId) {
|
private File getUserSystemDirectory(int userId) {
|
||||||
@@ -1690,7 +1700,7 @@ public final class Settings implements Watchable, Snappable, ResilientAtomicFile
|
|||||||
throws XmlPullParserException, IOException {
|
throws XmlPullParserException, IOException {
|
||||||
String defaultBrowser = readDefaultApps(parser);
|
String defaultBrowser = readDefaultApps(parser);
|
||||||
if (defaultBrowser != null) {
|
if (defaultBrowser != null) {
|
||||||
mDefaultBrowserApp.put(userId, defaultBrowser);
|
mPendingDefaultBrowser.put(userId, defaultBrowser);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2100,7 +2110,7 @@ public final class Settings implements Watchable, Snappable, ResilientAtomicFile
|
|||||||
|
|
||||||
void writeDefaultAppsLPr(XmlSerializer serializer, int userId)
|
void writeDefaultAppsLPr(XmlSerializer serializer, int userId)
|
||||||
throws IllegalArgumentException, IllegalStateException, IOException {
|
throws IllegalArgumentException, IllegalStateException, IOException {
|
||||||
String defaultBrowser = mDefaultBrowserApp.get(userId);
|
String defaultBrowser = mPendingDefaultBrowser.get(userId);
|
||||||
writeDefaultApps(serializer, defaultBrowser);
|
writeDefaultApps(serializer, defaultBrowser);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user