Skip to content

Commit b5f4dab

Browse files
rmp22joeyhuab
authored andcommitted
Adding theme engine interface
Change-Id: I64d455835389acb2e591ff0b623797e1e122f06d Signed-off-by: rmp22 <195054967+rmp22@users.noreply.github.com> Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
1 parent cd5e746 commit b5f4dab

21 files changed

Lines changed: 1787 additions & 28 deletions

File tree

cmds/idmap2/libidmap2/ResourceMapping.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ Result<Unit> CheckOverlayable(const TargetResourceContainer& target,
5353
const PolicyBitmask& fulfilled_policies,
5454
const ResourceId& target_resource) {
5555
constexpr const PolicyBitmask kDefaultPolicies =
56-
PolicyFlags::ODM_PARTITION | PolicyFlags::OEM_PARTITION | PolicyFlags::SYSTEM_PARTITION |
57-
PolicyFlags::VENDOR_PARTITION | PolicyFlags::PRODUCT_PARTITION | PolicyFlags::SIGNATURE |
58-
PolicyFlags::CONFIG_SIGNATURE;
56+
PolicyFlags::PUBLIC | PolicyFlags::ODM_PARTITION | PolicyFlags::OEM_PARTITION |
57+
PolicyFlags::SYSTEM_PARTITION | PolicyFlags::VENDOR_PARTITION |
58+
PolicyFlags::PRODUCT_PARTITION | PolicyFlags::SIGNATURE | PolicyFlags::CONFIG_SIGNATURE;
5959

6060
// If the resource does not have an overlayable definition, allow the resource to be overlaid if
6161
// the overlay is preinstalled, signed with the same signature as the target or signed with the
@@ -131,7 +131,6 @@ Result<ResourceMapping> ResourceMapping::FromContainers(const TargetResourceCont
131131
}
132132

133133
if (enforce_overlayable) {
134-
// Filter out resources the overlay is not allowed to override.
135134
auto overlayable = CheckOverlayable(target, overlay_info, fulfilled_policies, *target_resid);
136135
if (!overlayable) {
137136
log_info.Warning(LogMessage() << "overlay '" << overlay.GetPath()

core/java/android/content/Context.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6617,6 +6617,11 @@ public final <T> T getSystemService(@NonNull Class<T> serviceClass) {
66176617
*/
66186618
public static final String RESOURCES_SERVICE = "resources";
66196619

6620+
/**
6621+
* @hide
6622+
*/
6623+
public static final String THEME_ENGINE_SERVICE = "theme_engine";
6624+
66206625
/**
66216626
* Use with {@link #getSystemService(String)} to retrieve a
66226627
* {android.os.IIdmap2} for managing idmap files (used by overlay

core/java/android/content/pm/LauncherActivityInfo.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,21 @@ public CharSequence getLabel() {
127127
* @return The drawable associated with the activity.
128128
*/
129129
public Drawable getIcon(int density) {
130+
try {
131+
ComponentName cn = getComponentName();
132+
final Resources resources = mPm.getResourcesForApplication(
133+
getActivityInfo().applicationInfo);
134+
if (cn != null && resources != null) {
135+
Drawable themedIcon = resources.getIconPackOverride(
136+
cn.getPackageName(), cn.getClassName(), density);
137+
if (themedIcon != null) {
138+
return themedIcon;
139+
}
140+
}
141+
} catch (Exception e) {
142+
android.util.Log.d("LauncherActivityInfo", "Icon pack override failed", e);
143+
}
144+
130145
// TODO: Go through LauncherAppsService
131146
final int iconRes = getActivityInfo().getIconResource();
132147
Drawable icon = null;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package android.content.res;
2+
3+
/** @hide */
4+
oneway interface IThemeEngineCallback {
5+
void onThemeChanged(String category);
6+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package android.content.res;
2+
3+
import android.content.ComponentName;
4+
import android.content.res.IThemeEngineCallback;
5+
import android.graphics.Bitmap;
6+
7+
/** @hide */
8+
interface IThemeEngineManager {
9+
Bitmap getIconPackIcon(in ComponentName component, int density);
10+
boolean hasActiveIconPack();
11+
String getIconPackPackage();
12+
13+
Bitmap getPerAppIconPackIcon(String packageName, String className, int density);
14+
void setPerAppIconPack(String packageName, String iconPackPackage);
15+
void clearPerAppIconPack(String packageName);
16+
String getPerAppIconPack(String packageName);
17+
List<String> getInstalledIconPacks();
18+
19+
Bitmap getSystemThemeIconDrawable(String resourceName, int density);
20+
boolean isTargetedResource(String resourceName);
21+
boolean hasActiveSystemThemeIcons();
22+
String getActiveSystemThemeIcons();
23+
24+
String getCategoryTheme(String category);
25+
26+
void registerCallback(IThemeEngineCallback callback);
27+
void unregisterCallback(IThemeEngineCallback callback);
28+
void notifyThemeChanged(String category);
29+
30+
List<String> getAvailableOverlays(String category);
31+
}

core/java/android/content/res/Resources.java

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import android.app.LocaleConfig;
4646
import android.app.ResourcesManager;
4747
import android.compat.annotation.UnsupportedAppUsage;
48+
import android.content.ComponentName;
4849
import android.content.Context;
4950
import android.content.pm.ActivityInfo;
5051
import android.content.pm.ActivityInfo.Config;
@@ -251,6 +252,47 @@ public static Resources getSystem() {
251252
}
252253
}
253254

255+
/** @hide */
256+
@Nullable
257+
public Drawable getIconPackOverride(
258+
@NonNull String packageName, @NonNull String className, int density) {
259+
try {
260+
ThemeEngine themeEngine = ThemeEngine.getInstance();
261+
if (themeEngine == null) return null;
262+
ComponentName cn = new ComponentName(packageName, className);
263+
return themeEngine.getIconPackDrawable(cn, density);
264+
} catch (Exception e) {
265+
return null;
266+
}
267+
}
268+
269+
/** @hide */
270+
@Nullable
271+
public Drawable getIconPackOverride(
272+
@NonNull String packageName, @NonNull String className) {
273+
return getIconPackOverride(packageName, className, 0);
274+
}
275+
276+
/** @hide */
277+
public boolean hasActiveIconPack() {
278+
try {
279+
ThemeEngine themeEngine = ThemeEngine.getInstance();
280+
return themeEngine != null && themeEngine.hasActiveIconPack();
281+
} catch (Exception e) {
282+
return false;
283+
}
284+
}
285+
286+
/** @hide */
287+
public String getIconPackPackage() {
288+
try {
289+
ThemeEngine themeEngine = ThemeEngine.getInstance();
290+
return themeEngine != null ? themeEngine.getIconPackPackage() : null;
291+
} catch (Exception e) {
292+
return null;
293+
}
294+
}
295+
254296
/**
255297
* This exception is thrown by the resource APIs when a requested resource
256298
* can not be found.
@@ -1026,9 +1068,31 @@ public Drawable getDrawableForDensity(@DrawableRes int id, int density, @Nullabl
10261068
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
10271069
Drawable loadDrawable(@NonNull TypedValue value, int id, int density, @Nullable Theme theme)
10281070
throws NotFoundException {
1071+
return loadDrawableInternal(value, id, density, theme);
1072+
}
1073+
1074+
/** @hide */
1075+
@NonNull
1076+
public Drawable loadDrawableInternal(@NonNull TypedValue value, int id, int density,
1077+
@Nullable Theme theme) throws NotFoundException {
10291078
return mResourcesImpl.loadDrawable(this, value, id, density, theme);
10301079
}
10311080

1081+
/** @hide */
1082+
@Nullable
1083+
public Drawable getDrawableInternal(@DrawableRes int id) {
1084+
final TypedValue value = obtainTempTypedValue();
1085+
try {
1086+
final ResourcesImpl impl = mResourcesImpl;
1087+
impl.getValueForDensity(id, 0, value, true);
1088+
return loadDrawableInternal(value, id, 0, null);
1089+
} catch (Exception e) {
1090+
return null;
1091+
} finally {
1092+
releaseTempTypedValue(value);
1093+
}
1094+
}
1095+
10321096
/**
10331097
* Return a movie object associated with the particular resource ID.
10341098
* @param id The desired resource identifier, as generated by the aapt

0 commit comments

Comments
 (0)