• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.settings.wrapper;
18 
19 import android.content.Context;
20 import android.content.om.IOverlayManager;
21 import android.content.om.OverlayInfo;
22 import android.os.RemoteException;
23 import android.os.ServiceManager;
24 
25 import java.util.ArrayList;
26 import java.util.List;
27 
28 public class OverlayManagerWrapper {
29 
30     private final IOverlayManager mOverlayManager;
31 
OverlayManagerWrapper(IOverlayManager overlayManager)32     public OverlayManagerWrapper(IOverlayManager overlayManager) {
33         mOverlayManager = overlayManager;
34     }
35 
OverlayManagerWrapper()36     public OverlayManagerWrapper() {
37         this(IOverlayManager.Stub.asInterface(ServiceManager.getService(Context.OVERLAY_SERVICE)));
38     }
39 
getOverlayInfosForTarget(String overlay, int userId)40     public List<OverlayInfo> getOverlayInfosForTarget(String overlay, int userId) {
41         if (mOverlayManager == null) {
42             return new ArrayList<>();
43         }
44         try {
45             List<android.content.om.OverlayInfo> infos
46                     = mOverlayManager.getOverlayInfosForTarget(overlay, userId);
47             ArrayList<OverlayInfo> result = new ArrayList<>(infos.size());
48             for (int i = 0; i < infos.size(); i++) {
49                 result.add(new OverlayInfo(infos.get(i)));
50             }
51             return result;
52         } catch (RemoteException e) {
53             throw e.rethrowFromSystemServer();
54         }
55     }
56 
setEnabled(String overlay, boolean enabled, int userId)57     public boolean setEnabled(String overlay, boolean enabled, int userId) {
58         if (mOverlayManager == null) {
59             return false;
60         }
61         try {
62             return mOverlayManager.setEnabled(overlay, enabled, userId);
63         } catch (RemoteException e) {
64             throw e.rethrowFromSystemServer();
65         }
66     }
67 
setEnabledExclusiveInCategory(String overlay, int userId)68     public boolean setEnabledExclusiveInCategory(String overlay, int userId) {
69         if (mOverlayManager == null) {
70             return false;
71         }
72         try {
73             return mOverlayManager.setEnabledExclusiveInCategory(overlay, userId);
74         } catch (RemoteException e) {
75             throw e.rethrowFromSystemServer();
76         }
77     }
78 
79     public static class OverlayInfo {
80 
81         public static final String CATEGORY_THEME = android.content.om.OverlayInfo.CATEGORY_THEME;
82         public final String packageName;
83         public final String category;
84         private final boolean mEnabled;
85 
OverlayInfo(String packageName, String category, boolean enabled)86         public OverlayInfo(String packageName, String category, boolean enabled) {
87             this.packageName = packageName;
88             this.category = category;
89             mEnabled = enabled;
90         }
91 
OverlayInfo(android.content.om.OverlayInfo info)92         public OverlayInfo(android.content.om.OverlayInfo info) {
93             mEnabled = info.isEnabled();
94             category = info.category;
95             packageName = info.packageName;
96         }
97 
isEnabled()98         public boolean isEnabled() {
99             return mEnabled;
100         }
101     }
102 }
103