Skip to content

Commit

Permalink
base: modify/define custom overlay management
Browse files Browse the repository at this point in the history
Change-Id: I37376416fdd847e354075d31ee3ecd1f83df0cc7
Signed-off-by: Harsh Shandilya <harsh@prjkt.io>
Signed-off-by: VenkatVishalV <venkatvishal124@gmail.com>
  • Loading branch information
Surge1223 authored and VenkatVishalV committed Nov 10, 2018
1 parent 6228e45 commit 005ac3b
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 5 deletions.
25 changes: 25 additions & 0 deletions core/java/android/content/substratum/ISubstratumService.aidl
Original file line number Diff line number Diff line change
Expand Up @@ -140,5 +140,30 @@ interface ISubstratumService {
* requested user, an empty map is returned.
*/
Map getAllOverlays(in int uid);

/**
* Request that an overlay package be enabled or disabled when possible to
* do so.
*
* It is always possible to disable an overlay, but due to technical and
* security reasons it may not always be possible to enable an overlay. An
* example of the latter is when the related target package is not
* installed. If the technical obstacle is later overcome, the overlay is
* automatically enabled at that point in time.
*
* An enabled overlay is a part of target package's resources, i.e. it will
* be part of any lookups performed via {@link android.content.res.Resources}
* and {@link android.content.res.AssetManager}. A disabled overlay will no
* longer affect the resources of the target package. If the target is
* currently running, its outdated resources will be replaced by new ones.
* This happens the same way as when an application enters or exits split
* window mode.
*
* @param packageName The name of the overlay package.
* @param enable true to enable the overlay, false to disable it.
* @param userId The user for which to change the overlay.
* @return true if the system successfully registered the request, false otherwise.
*/
boolean setEnabled(in String packageName, in boolean enable, in int userId);
}

4 changes: 3 additions & 1 deletion core/jni/fd_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,15 @@ bool FileDescriptorWhitelist::IsAllowed(const std::string& path) const {
static const char* kOverlaySubdir = "/system/vendor/overlay-subdir/";
static const char* kSystemProductOverlayDir = "/system/product/overlay/";
static const char* kProductOverlayDir = "/product/overlay";
static const char* kThemeOverlayDir = "/data/system/theme";
static const char* kApkSuffix = ".apk";

if ((android::base::StartsWith(path, kOverlayDir)
|| android::base::StartsWith(path, kOverlaySubdir)
|| android::base::StartsWith(path, kVendorOverlayDir)
|| android::base::StartsWith(path, kSystemProductOverlayDir)
|| android::base::StartsWith(path, kProductOverlayDir))
|| android::base::StartsWith(path, kProductOverlayDir)
|| android::base::StartsWith(path, kThemeOverlayDir))
&& android::base::EndsWith(path, kApkSuffix)
&& path.find("/../") == std::string::npos) {
return true;
Expand Down
3 changes: 2 additions & 1 deletion libs/androidfw/AssetManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ static volatile int32_t gCount = 0;
const char* AssetManager::RESOURCES_FILENAME = "resources.arsc";
const char* AssetManager::IDMAP_BIN = "/system/bin/idmap";
const char* AssetManager::OVERLAY_DIR = "/vendor/overlay";
const char* AssetManager::THEME_OVERLAY_DIR = "/data/system/theme";
const char* AssetManager::PRODUCT_OVERLAY_DIR = "/product/overlay";
const char* AssetManager::OVERLAY_THEME_DIR_PROPERTY = "ro.boot.vendor.overlay.theme";
const char* AssetManager::OVERLAY_THEME_DIR_PROPERTY = "../../data/system/theme";
const char* AssetManager::TARGET_PACKAGE_NAME = "android";
const char* AssetManager::TARGET_APK_PATH = "/system/framework/framework-res.apk";
const char* AssetManager::IDMAP_DIR = "/data/resource-cache";
Expand Down
1 change: 1 addition & 0 deletions libs/androidfw/include/androidfw/AssetManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class AssetManager : public AAssetManager {
static const char* RESOURCES_FILENAME;
static const char* IDMAP_BIN;
static const char* OVERLAY_DIR;
static const char* THEME_OVERLAY_DIR;
static const char* PRODUCT_OVERLAY_DIR;
/*
* If OVERLAY_THEME_DIR_PROPERTY is set, search for runtime resource overlay
Expand Down
1 change: 1 addition & 0 deletions packages/SubstratumService/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL"/>
<uses-permission android:name="android.permission.CHANGE_OVERLAY_PACKAGES"/>
<uses-feature name="projekt.substratum.theme" required="true"/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,6 @@ public OverlayInfo getOverlayInfo(@Nullable final String packageName,
@Override
public boolean setEnabled(@Nullable final String packageName, final boolean enable,
int userId) throws RemoteException {
enforceChangeOverlayPackagesPermission("setEnabled");
userId = handleIncomingUser(userId, "setEnabled");
if (packageName == null) {
return false;
Expand All @@ -558,7 +557,6 @@ public boolean setEnabled(@Nullable final String packageName, final boolean enab
@Override
public boolean setEnabledExclusive(@Nullable final String packageName, final boolean enable,
int userId) throws RemoteException {
enforceChangeOverlayPackagesPermission("setEnabled");
userId = handleIncomingUser(userId, "setEnabled");
if (packageName == null || !enable) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@ public class PackageManagerService extends IPackageManager.Stub
static final int SCAN_AS_OEM = 1<<19;
static final int SCAN_AS_VENDOR = 1<<20;
static final int SCAN_AS_PRODUCT = 1<<21;
static final int SCAN_AS_THEME = 1<<22;

@IntDef(flag = true, prefix = { "SCAN_" }, value = {
SCAN_NO_DEX,
Expand Down Expand Up @@ -580,6 +581,8 @@ public class PackageManagerService extends IPackageManager.Stub

private static final String PRODUCT_OVERLAY_DIR = "/product/overlay";

private static final String THEME_OVERLAY_DIR = "/data/system/theme";

/** Canonical intent used to identify what counts as a "web browser" app */
private static final Intent sBrowserIntent;
static {
Expand Down Expand Up @@ -2631,6 +2634,15 @@ public void onDefaultRuntimePermissionsGranted(int userId) {
| SCAN_AS_SYSTEM
| SCAN_AS_PRODUCT,
0);
scanDirTracedLI(new File(THEME_OVERLAY_DIR),
mDefParseFlags
| PackageParser.PARSE_IS_SYSTEM_DIR,
scanFlags
| SCAN_AS_SYSTEM
| SCAN_AS_PRODUCT
| SCAN_AS_THEME,
0);


mParallelPackageParserCallback.findStaticOverlayPackages();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import static android.os.Binder.getCallingUid;

public final class SubstratumService extends SystemService {

Expand Down Expand Up @@ -633,7 +634,25 @@ public Map getAllOverlays(int uid) {
return null;
}
}
};

@Override
public boolean setEnabled(final String packageName, final boolean enable,
int userId) throws RemoteException {
userId = Binder.getCallingUid();
if (packageName == null) {
return false;
}
log("setEnabled - File name = \'" + packageName + "\'");
final long ident = Binder.clearCallingIdentity();
try {
synchronized (mLock) {
return mOm.setEnabled(packageName, enable, UserHandle.USER_SYSTEM);
}
} finally {
Binder.restoreCallingIdentity(ident);
}
}
};

private Context getAppContext(String packageName) {
Context ctx = null;
Expand Down

0 comments on commit 005ac3b

Please sign in to comment.