diff options
10 files changed, 441 insertions, 200 deletions
diff --git a/core/java/com/android/internal/service/wallpaper/ImageWallpaper.java b/core/java/com/android/internal/service/wallpaper/ImageWallpaper.java index 7266ee3..bfe8696 100644 --- a/core/java/com/android/internal/service/wallpaper/ImageWallpaper.java +++ b/core/java/com/android/internal/service/wallpaper/ImageWallpaper.java @@ -59,6 +59,7 @@ public class ImageWallpaper extends WallpaperService { class WallpaperObserver extends BroadcastReceiver { public void onReceive(Context context, Intent intent) { mEngine.updateWallpaper(); + mEngine.drawFrame(); } } @@ -72,14 +73,7 @@ public class ImageWallpaper extends WallpaperService { @Override public void onCreate(SurfaceHolder surfaceHolder) { super.onCreate(surfaceHolder); - mBackground = mWallpaperManager.getDrawable(); - mBounds.left = mBounds.top = 0; - mBounds.right = mBackground.getIntrinsicWidth(); - mBounds.bottom = mBackground.getIntrinsicHeight(); - int offx = (getDesiredMinimumWidth() - mBounds.right) / 2; - int offy = (getDesiredMinimumHeight() - mBounds.bottom) / 2; - mBounds.offset(offx, offy); - mBackground.setBounds(mBounds); + updateWallpaper(); surfaceHolder.setSizeFromLayout(); } @@ -131,6 +125,13 @@ public class ImageWallpaper extends WallpaperService { void updateWallpaper() { synchronized (mLock) { mBackground = mWallpaperManager.getDrawable(); + mBounds.left = mBounds.top = 0; + mBounds.right = mBackground.getIntrinsicWidth(); + mBounds.bottom = mBackground.getIntrinsicHeight(); + int offx = (getDesiredMinimumWidth() - mBounds.right) / 2; + int offy = (getDesiredMinimumHeight() - mBounds.bottom) / 2; + mBounds.offset(offx, offy); + mBackground.setBounds(mBounds); } } } diff --git a/media/java/android/media/AudioManager.java b/media/java/android/media/AudioManager.java index 60fc0e0..16bf8a2 100644 --- a/media/java/android/media/AudioManager.java +++ b/media/java/android/media/AudioManager.java @@ -153,20 +153,6 @@ public class AudioManager { @Deprecated public static final int NUM_STREAMS = AudioSystem.NUM_STREAMS; - /** @hide Maximum volume index values for audio streams */ - public static final int[] MAX_STREAM_VOLUME = new int[] { - 6, // STREAM_VOICE_CALL - 8, // STREAM_SYSTEM - 8, // STREAM_RING - 16, // STREAM_MUSIC - 8, // STREAM_ALARM - 8, // STREAM_NOTIFICATION - 16, // STREAM_BLUETOOTH_SCO - 8, // STREAM_SYSTEM_ENFORCED - 16, // STREAM_DTMF - 16 // STREAM_TTS - }; - /** @hide Default volume index values for audio streams */ public static final int[] DEFAULT_STREAM_VOLUME = new int[] { 4, // STREAM_VOICE_CALL diff --git a/media/java/android/media/AudioService.java b/media/java/android/media/AudioService.java index 9afe6a1..5a59712 100644 --- a/media/java/android/media/AudioService.java +++ b/media/java/android/media/AudioService.java @@ -44,6 +44,7 @@ import android.provider.Settings; import android.provider.Settings.System; import android.util.Log; import android.view.VolumePanel; +import android.os.SystemProperties; import com.android.internal.telephony.ITelephony; @@ -54,6 +55,7 @@ import java.util.Iterator; import java.util.Map; import java.util.Set; + /** * The implementation of the volume manager service. * <p> @@ -140,6 +142,19 @@ public class AudioService extends IAudioService.Stub { {4, -1} // FX_FOCUS_RETURN }; + /** @hide Maximum volume index values for audio streams */ + private int[] MAX_STREAM_VOLUME = new int[] { + 6, // STREAM_VOICE_CALL + 8, // STREAM_SYSTEM + 8, // STREAM_RING + 16, // STREAM_MUSIC + 8, // STREAM_ALARM + 8, // STREAM_NOTIFICATION + 16, // STREAM_BLUETOOTH_SCO + 8, // STREAM_SYSTEM_ENFORCED + 16, // STREAM_DTMF + 16 // STREAM_TTS + }; /* STREAM_VOLUME_ALIAS[] indicates for each stream if it uses the volume settings * of another stream: This avoids multiplying the volume settings for hidden * stream types that follow other stream behavior for volume settings @@ -231,6 +246,12 @@ public class AudioService extends IAudioService.Stub { public AudioService(Context context) { mContext = context; mContentResolver = context.getContentResolver(); + + // Intialized volume + MAX_STREAM_VOLUME[AudioSystem.STREAM_VOICE_CALL] = SystemProperties.getInt( + "ro.config.vc_call_vol_steps", + MAX_STREAM_VOLUME[AudioSystem.STREAM_VOICE_CALL]); + mVolumePanel = new VolumePanel(context, this); mSettingsObserver = new SettingsObserver(); mMode = AudioSystem.MODE_NORMAL; @@ -249,6 +270,7 @@ public class AudioService extends IAudioService.Stub { intentFilter.addAction(BluetoothA2dp.SINK_STATE_CHANGED_ACTION); intentFilter.addAction(BluetoothIntent.HEADSET_STATE_CHANGED_ACTION); context.registerReceiver(mReceiver, intentFilter); + } private void createAudioSystemThread() { @@ -945,7 +967,7 @@ public class AudioService extends IAudioService.Stub { mStreamType = streamType; final ContentResolver cr = mContentResolver; - mIndexMax = AudioManager.MAX_STREAM_VOLUME[streamType]; + mIndexMax = MAX_STREAM_VOLUME[streamType]; mIndex = Settings.System.getInt(cr, mVolumeIndexSettingName, AudioManager.DEFAULT_STREAM_VOLUME[streamType]); diff --git a/services/java/com/android/server/WallpaperManagerService.java b/services/java/com/android/server/WallpaperManagerService.java index 9fe4eee..0a31396 100644 --- a/services/java/com/android/server/WallpaperManagerService.java +++ b/services/java/com/android/server/WallpaperManagerService.java @@ -38,6 +38,7 @@ import android.os.FileObserver; import android.os.ParcelFileDescriptor; import android.os.RemoteCallbackList; import android.os.ServiceManager; +import android.os.SystemClock; import android.service.wallpaper.IWallpaperConnection; import android.service.wallpaper.IWallpaperEngine; import android.service.wallpaper.IWallpaperService; @@ -68,10 +69,16 @@ class WallpaperManagerService extends IWallpaperManager.Stub { Object mLock = new Object(); - private static final File WALLPAPER_DIR = new File( + /** + * Minimum time between crashes of a wallpaper service for us to consider + * restarting it vs. just reverting to the static wallpaper. + */ + static final long MIN_WALLPAPER_CRASH_TIME = 10000; + + static final File WALLPAPER_DIR = new File( "/data/data/com.android.settings/files"); - private static final String WALLPAPER = "wallpaper"; - private static final File WALLPAPER_FILE = new File(WALLPAPER_DIR, WALLPAPER); + static final String WALLPAPER = "wallpaper"; + static final File WALLPAPER_FILE = new File(WALLPAPER_DIR, WALLPAPER); /** * List of callbacks registered they should each be notified @@ -116,6 +123,7 @@ class WallpaperManagerService extends IWallpaperManager.Stub { String mName = ""; ComponentName mWallpaperComponent; WallpaperConnection mWallpaperConnection; + long mLastDiedTime; class WallpaperConnection extends IWallpaperConnection.Stub implements ServiceConnection { @@ -136,6 +144,14 @@ class WallpaperManagerService extends IWallpaperManager.Stub { synchronized (mLock) { mService = null; mEngine = null; + if (mWallpaperConnection == this) { + Log.w(TAG, "Wallpaper service gone: " + mWallpaperComponent); + if ((mLastDiedTime+MIN_WALLPAPER_CRASH_TIME) + < SystemClock.uptimeMillis()) { + Log.w(TAG, "Reverting to built-in wallpaper!"); + bindWallpaperComponentLocked(null); + } + } } } @@ -195,7 +211,12 @@ class WallpaperManagerService extends IWallpaperManager.Stub { if (f.exists()) { f.delete(); } - bindWallpaperComponentLocked(null); + final long ident = Binder.clearCallingIdentity(); + try { + bindWallpaperComponentLocked(null); + } finally { + Binder.restoreCallingIdentity(ident); + } } } @@ -247,12 +268,17 @@ class WallpaperManagerService extends IWallpaperManager.Stub { public ParcelFileDescriptor setWallpaper(String name) { checkPermission(android.Manifest.permission.SET_WALLPAPER); synchronized (mLock) { - ParcelFileDescriptor pfd = updateWallpaperBitmapLocked(name); - if (pfd != null) { - bindWallpaperComponentLocked(null); - saveSettingsLocked(); + final long ident = Binder.clearCallingIdentity(); + try { + ParcelFileDescriptor pfd = updateWallpaperBitmapLocked(name); + if (pfd != null) { + bindWallpaperComponentLocked(null); + saveSettingsLocked(); + } + return pfd; + } finally { + Binder.restoreCallingIdentity(ident); } - return pfd; } } @@ -341,6 +367,7 @@ class WallpaperManagerService extends IWallpaperManager.Stub { clearWallpaperComponentLocked(); mWallpaperComponent = name; mWallpaperConnection = newConn; + mLastDiedTime = SystemClock.uptimeMillis(); try { if (DEBUG) Log.v(TAG, "Adding window token: " + newConn.mToken); mIWindowManager.addWindowToken(newConn.mToken, diff --git a/services/java/com/android/server/WindowManagerService.java b/services/java/com/android/server/WindowManagerService.java index 2ff73bb..ac80071 100644 --- a/services/java/com/android/server/WindowManagerService.java +++ b/services/java/com/android/server/WindowManagerService.java @@ -1194,6 +1194,9 @@ public class WindowManagerService extends IWindowManager.Stub } if (!visible) w = null; + //if (mWallpaperTarget != w) { + // Log.v(TAG, "New wallpaper target: " + w); + //} mWallpaperTarget = w; if (visible) { @@ -6900,10 +6903,10 @@ public class WindowManagerService extends IWindowManager.Stub if (atoken != null) { return mSurface != null && mPolicyVisibility && !mDestroying && ((!mAttachedHidden && !atoken.hiddenRequested) - || mAnimating || atoken.animating); + || mAnimation != null || atoken.animation != null); } else { return mSurface != null && mPolicyVisibility && !mDestroying - && (!mAttachedHidden || mAnimating); + && (!mAttachedHidden || mAnimation != null); } } @@ -6913,10 +6916,11 @@ public class WindowManagerService extends IWindowManager.Stub */ boolean isReadyForDisplay() { final AppWindowToken atoken = mAppToken; - final boolean animating = atoken != null ? atoken.animating : false; + final boolean animating = atoken != null + ? (atoken.animation != null) : false; return mSurface != null && mPolicyVisibility && !mDestroying && ((!mAttachedHidden && !mRootToken.hidden) - || mAnimating || animating); + || mAnimation != null || animating); } /** Is the window or its container currently animating? */ diff --git a/tools/layoutlib/bridge/src/android/os/ServiceManager.java b/tools/layoutlib/bridge/src/android/os/ServiceManager.java new file mode 100644 index 0000000..6a68ee2 --- /dev/null +++ b/tools/layoutlib/bridge/src/android/os/ServiceManager.java @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2009 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 android.os; + +import java.util.Map; + +public final class ServiceManager { + + /** + * Returns a reference to a service with the given name. + * + * @param name the name of the service to get + * @return a reference to the service, or <code>null</code> if the service doesn't exist + */ + public static IBinder getService(String name) { + return null; + } + + /** + * Place a new @a service called @a name into the service + * manager. + * + * @param name the name of the new service + * @param service the service object + */ + public static void addService(String name, IBinder service) { + // pass + } + + /** + * Retrieve an existing service called @a name from the + * service manager. Non-blocking. + */ + public static IBinder checkService(String name) { + return null; + } + + /** + * Return a list of all currently running services. + */ + public static String[] listServices() throws RemoteException { + // actual implementation returns null sometimes, so it's ok + // to return null instead of an empty list. + return null; + } + + /** + * This is only intended to be called when the process is first being brought + * up and bound by the activity manager. There is only one thread in the process + * at that time, so no locking is done. + * + * @param cache the cache of service references + * @hide + */ + public static void initServiceCache(Map<String, IBinder> cache) { + // pass + } +} diff --git a/tools/layoutlib/bridge/src/android/view/accessibility/AccessibilityManager.java b/tools/layoutlib/bridge/src/android/view/accessibility/AccessibilityManager.java new file mode 100644 index 0000000..251c053 --- /dev/null +++ b/tools/layoutlib/bridge/src/android/view/accessibility/AccessibilityManager.java @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2009 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 android.view.accessibility; + +import android.content.Context; +import android.content.pm.ServiceInfo; + +import java.util.Collections; +import java.util.List; + +/** + * System level service that serves as an event dispatch for {@link AccessibilityEvent}s. + * Such events are generated when something notable happens in the user interface, + * for example an {@link android.app.Activity} starts, the focus or selection of a + * {@link android.view.View} changes etc. Parties interested in handling accessibility + * events implement and register an accessibility service which extends + * {@link android.accessibilityservice.AccessibilityService}. + * + * @see AccessibilityEvent + * @see android.accessibilityservice.AccessibilityService + * @see android.content.Context#getSystemService + */ +public final class AccessibilityManager { + private static AccessibilityManager sInstance = new AccessibilityManager(); + + /** + * Get an AccessibilityManager instance (create one if necessary). + * + * @hide + */ + public static AccessibilityManager getInstance(Context context) { + return sInstance; + } + + /** + * Create an instance. + * + * @param context A {@link Context}. + */ + private AccessibilityManager() { + } + + /** + * Returns if the {@link AccessibilityManager} is enabled. + * + * @return True if this {@link AccessibilityManager} is enabled, false otherwise. + */ + public boolean isEnabled() { + return false; + } + + /** + * Sends an {@link AccessibilityEvent}. If this {@link AccessibilityManager} is not + * enabled the call is a NOOP. + * + * @param event The {@link AccessibilityEvent}. + * + * @throws IllegalStateException if a client tries to send an {@link AccessibilityEvent} + * while accessibility is not enabled. + */ + public void sendAccessibilityEvent(AccessibilityEvent event) { + } + + /** + * Requests interruption of the accessibility feedback from all accessibility services. + */ + public void interrupt() { + } + + /** + * Returns the {@link ServiceInfo}s of the installed accessibility services. + * + * @return An unmodifiable list with {@link ServiceInfo}s. + */ + public List<ServiceInfo> getAccessibilityServiceList() { + // normal implementation does this in some case, so let's do the same + // (unmodifiableList wrapped around null). + List<ServiceInfo> services = null; + return Collections.unmodifiableList(services); + } +} diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeContext.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeContext.java index 69f3d9c..f48c8db 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeContext.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeContext.java @@ -64,7 +64,7 @@ import java.util.Map.Entry; * Custom implementation of Context to handle non compiled resources. */ public final class BridgeContext extends Context { - + private Resources mResources; private Theme mTheme; private HashMap<View, Object> mViewKeyMap = new HashMap<View, Object>(); @@ -73,12 +73,12 @@ public final class BridgeContext extends Context { private Map<String, Map<String, IResourceValue>> mProjectResources; private Map<String, Map<String, IResourceValue>> mFrameworkResources; private Map<IStyleResourceValue, IStyleResourceValue> mStyleInheritanceMap; - + // maps for dynamically generated id representing style objects (IStyleResourceValue) private Map<Integer, IStyleResourceValue> mDynamicIdToStyleMap; private Map<IStyleResourceValue, Integer> mStyleToDynamicIdMap; private int mDynamicIdGenerator = 0x01030000; // Base id for framework R.style - + // cache for TypedArray generated from IStyleResourceValue object private Map<int[], Map<Integer, TypedArray>> mTypedArrayCache; private BridgeInflater mInflater; @@ -112,7 +112,7 @@ public final class BridgeContext extends Context { mProjectCallback = customViewLoader; mLogger = logger; Configuration config = new Configuration(); - + AssetManager assetManager = BridgeAssetManager.initSystem(); mResources = BridgeResources.initSystem( this, @@ -120,19 +120,19 @@ public final class BridgeContext extends Context { metrics, config, customViewLoader); - + mTheme = mResources.newTheme(); - + mThemeValues = currentTheme; mProjectResources = projectResources; mFrameworkResources = frameworkResources; mStyleInheritanceMap = styleInheritanceMap; } - + public void setBridgeInflater(BridgeInflater inflater) { mInflater = inflater; } - + public void addViewKey(View view, Object viewKey) { mViewKeyMap.put(view, viewKey); } @@ -140,19 +140,19 @@ public final class BridgeContext extends Context { public Object getViewKey(View view) { return mViewKeyMap.get(view); } - + public Object getProjectKey() { return mProjectKey; } - + public IProjectCallback getProjectCallback() { return mProjectCallback; } - + public ILayoutLog getLogger() { return mLogger; } - + // ------------ Context methods @Override @@ -169,14 +169,14 @@ public final class BridgeContext extends Context { public ClassLoader getClassLoader() { return this.getClass().getClassLoader(); } - + @Override public Object getSystemService(String service) { if (LAYOUT_INFLATER_SERVICE.equals(service)) { return mInflater; } - - // AutoCompleteTextView and MultiAutoCompleteTextView want a window + + // AutoCompleteTextView and MultiAutoCompleteTextView want a window // service. We don't have any but it's not worth an exception. if (WINDOW_SERVICE.equals(service)) { return null; @@ -196,38 +196,38 @@ public final class BridgeContext extends Context { throws Resources.NotFoundException { // get the IStyleResourceValue based on the resId; IStyleResourceValue style = getStyleByDynamicId(resid); - + if (style == null) { throw new Resources.NotFoundException(); } if (mTypedArrayCache == null) { mTypedArrayCache = new HashMap<int[], Map<Integer,TypedArray>>(); - + Map<Integer, TypedArray> map = new HashMap<Integer, TypedArray>(); mTypedArrayCache.put(attrs, map); BridgeTypedArray ta = createStyleBasedTypedArray(style, attrs); map.put(resid, ta); - + return ta; } - + // get the 2nd map Map<Integer, TypedArray> map = mTypedArrayCache.get(attrs); if (map == null) { map = new HashMap<Integer, TypedArray>(); mTypedArrayCache.put(attrs, map); } - + // get the array from the 2nd map TypedArray ta = map.get(resid); - + if (ta == null) { ta = createStyleBasedTypedArray(style, attrs); map.put(resid, ta); } - + return ta; } @@ -235,11 +235,11 @@ public final class BridgeContext extends Context { public final TypedArray obtainStyledAttributes(AttributeSet set, int[] attrs) { return obtainStyledAttributes(set, attrs, 0, 0); } - + @Override public TypedArray obtainStyledAttributes(AttributeSet set, int[] attrs, int defStyleAttr, int defStyleRes) { - + // Hint: for XmlPullParser, attach source //DEVICE_SRC/dalvik/libcore/xml/src/java BridgeXmlBlockParser parser = null; if (set instanceof BridgeXmlBlockParser) { @@ -252,10 +252,10 @@ public final class BridgeContext extends Context { boolean[] frameworkAttributes = new boolean[1]; TreeMap<Integer, String> styleNameMap = searchAttrs(attrs, frameworkAttributes); - + BridgeTypedArray ta = ((BridgeResources) mResources).newTypeArray(attrs.length, parser.isPlatformFile()); - + // resolve the defStyleAttr value into a IStyleResourceValue IStyleResourceValue defStyleValues = null; if (defStyleAttr != 0) { @@ -265,7 +265,7 @@ public final class BridgeContext extends Context { // look for the style in the current theme, and its parent: if (mThemeValues != null) { IResourceValue item = findItemInStyle(mThemeValues, defStyleName); - + if (item != null) { // item is a reference to a style entry. Search for it. item = findResValue(item.getValue()); @@ -279,12 +279,12 @@ public final class BridgeContext extends Context { } } } - + if (defStyleRes != 0) { // FIXME: See what we need to do with this. throw new UnsupportedOperationException(); } - + String namespace = BridgeConstants.NS_RESOURCES; if (frameworkAttributes[0] == false) { // need to use the application namespace @@ -294,32 +294,32 @@ public final class BridgeContext extends Context { if (styleNameMap != null) { for (Entry<Integer, String> styleAttribute : styleNameMap.entrySet()) { int index = styleAttribute.getKey().intValue(); - + String name = styleAttribute.getValue(); String value = parser.getAttributeValue(namespace, name); - + // if there's no direct value for this attribute in the XML, we look for default // values in the widget defStyle, and then in the theme. if (value == null) { IResourceValue resValue = null; - + // look for the value in the defStyle first (and its parent if needed) if (defStyleValues != null) { resValue = findItemInStyle(defStyleValues, name); } - + // if the item is not present in the defStyle, we look in the main theme (and // its parent themes) if (resValue == null && mThemeValues != null) { resValue = findItemInStyle(mThemeValues, name); } - + // if we found a value, we make sure this doesn't reference another value. // So we resolve it. if (resValue != null) { resValue = resolveResValue(resValue); } - + ta.bridgeSetValue(index, name, resValue); } else { // there is a value in the XML, but we need to resolve it in case it's @@ -328,15 +328,20 @@ public final class BridgeContext extends Context { } } } - + ta.sealArray(); - + return ta; } - - + + @Override + public Looper getMainLooper() { + return Looper.myLooper(); + } + + // ------------- private new methods - + /** * Creates a {@link BridgeTypedArray} by filling the values defined by the int[] with the * values found in the given style. @@ -345,30 +350,30 @@ public final class BridgeContext extends Context { private BridgeTypedArray createStyleBasedTypedArray(IStyleResourceValue style, int[] attrs) throws Resources.NotFoundException { TreeMap<Integer, String> styleNameMap = searchAttrs(attrs, null); - + BridgeTypedArray ta = ((BridgeResources) mResources).newTypeArray(attrs.length, false /* platformResourceFlag */); - + // loop through all the values in the style map, and init the TypedArray with // the style we got from the dynamic id for (Entry<Integer, String> styleAttribute : styleNameMap.entrySet()) { int index = styleAttribute.getKey().intValue(); String name = styleAttribute.getValue(); - + // get the value from the style, or its parent styles. IResourceValue resValue = findItemInStyle(style, name); - + // resolve it to make sure there are no references left. ta.bridgeSetValue(index, name, resolveResValue(resValue)); } - + ta.sealArray(); return ta; } - + /** * Resolves the value of a resource, if the value references a theme or resource value. * <p/> @@ -391,13 +396,13 @@ public final class BridgeContext extends Context { // get the IResourceValue referenced by this value IResourceValue resValue = findResValue(value); - + // if resValue is null, but value is not null, this means it was not a reference. // we return the name/value wrapper in a IResourceValue if (resValue == null) { return new ResourceValue(type, name, value); } - + // we resolved a first reference, but we need to make sure this isn't a reference also. return resolveResValue(resValue); } @@ -411,7 +416,7 @@ public final class BridgeContext extends Context { * <p/> * If a value that does not need to be resolved is given, the method will return the input * value. - * + * * @param value the value containing the reference to resolve. * @return a {@link IResourceValue} object or <code>null</code> */ @@ -419,7 +424,7 @@ public final class BridgeContext extends Context { if (value == null) { return null; } - + // if the resource value is a style, we simply return it. if (value instanceof IStyleResourceValue) { return value; @@ -436,7 +441,7 @@ public final class BridgeContext extends Context { // otherwise, we attempt to resolve this new value as well return resolveResValue(resolvedValue); } - + /** * Searches for, and returns a {@link IResourceValue} by its reference. * <p/> @@ -451,7 +456,7 @@ public final class BridgeContext extends Context { * <p/> * The actual format of a reference is <pre>@[namespace:]resType/resName</pre> but this method * only support the android namespace. - * + * * @param reference the resource reference to search for. * @return a {@link IResourceValue} or <code>null</code>. */ @@ -481,7 +486,7 @@ public final class BridgeContext extends Context { // we look for the referenced item name. String referenceName = null; - + if (segments.length == 2) { // there was a resType in the reference. If it's attr, we ignore it // else, we assert for now. @@ -495,7 +500,7 @@ public final class BridgeContext extends Context { // it's just an item name. referenceName = segments[0]; } - + // now we look for android: in the referenceName in order to support format // such as: ?attr/android:name if (referenceName.startsWith(BridgeConstants.PREFIX_ANDROID)) { @@ -512,9 +517,9 @@ public final class BridgeContext extends Context { return findItemInStyle(mThemeValues, referenceName); } else if (reference.startsWith(BridgeConstants.PREFIX_RESOURCE_REF)) { boolean frameworkOnly = false; - + // check for the specific null reference value. - if (BridgeConstants.REFERENCE_NULL.equals(reference)) { + if (BridgeConstants.REFERENCE_NULL.equals(reference)) { return null; } @@ -526,20 +531,20 @@ public final class BridgeContext extends Context { } else { reference = reference.substring(BridgeConstants.PREFIX_RESOURCE_REF.length()); } - + // at this point, value contains type/[android:]name (drawable/foo for instance) String[] segments = reference.split("\\/"); - + // now we look for android: in the resource name in order to support format // such as: @drawable/android:name if (segments[1].startsWith(BridgeConstants.PREFIX_ANDROID)) { frameworkOnly = true; segments[1] = segments[1].substring(BridgeConstants.PREFIX_ANDROID.length()); } - + return findResValue(segments[0], segments[1], frameworkOnly); } - + // Looks like the value didn't reference anything. Return null. return null; } @@ -565,7 +570,7 @@ public final class BridgeContext extends Context { } } } - + // now search in the framework resources. typeMap = mFrameworkResources.get(resType); if (typeMap != null) { @@ -574,11 +579,11 @@ public final class BridgeContext extends Context { return item; } } - + // didn't find the resource anywhere. return null; } - + /** * Returns a framework resource by type and name. The returned resource is resolved. * @param resourceType the type of the resource @@ -587,7 +592,7 @@ public final class BridgeContext extends Context { public IResourceValue getFrameworkResource(String resourceType, String resourceName) { return getResource(resourceType, resourceName, mFrameworkResources); } - + /** * Returns a project resource by type and name. The returned resource is resolved. * @param resourceType the type of the resource @@ -596,7 +601,7 @@ public final class BridgeContext extends Context { public IResourceValue getProjectResource(String resourceType, String resourceName) { return getResource(resourceType, resourceName, mProjectResources); } - + IResourceValue getResource(String resourceType, String resourceName, Map<String, Map<String, IResourceValue>> resourceRepository) { Map<String, IResourceValue> typeMap = resourceRepository.get(resourceType); @@ -607,12 +612,12 @@ public final class BridgeContext extends Context { return item; } } - + // didn't find the resource anywhere. return null; - + } - + /** * Returns the {@link IResourceValue} matching a given name in a given style. If the * item is not directly available in the style, the method looks in its parent style. @@ -622,7 +627,7 @@ public final class BridgeContext extends Context { */ IResourceValue findItemInStyle(IStyleResourceValue style, String itemName) { IResourceValue item = style.findItem(itemName); - + // if we didn't find it, we look in the parent style (if applicable) if (item == null && mStyleInheritanceMap != null) { IStyleResourceValue parentStyle = mStyleInheritanceMap.get(style); @@ -630,7 +635,7 @@ public final class BridgeContext extends Context { return findItemInStyle(parentStyle, itemName); } } - + return item; } @@ -642,7 +647,7 @@ public final class BridgeContext extends Context { * attrs == com.android.internal.R.styleable.View, this returns the list of the "xyz" where * there's a field com.android.internal.R.styleable.View_xyz and the field value is the index * that is used to reference the attribute later in the TypedArray. - * + * * @param attrs An attribute array reference given to obtainStyledAttributes. * @return A sorted map Attribute-Value to Attribute-Name for all attributes declared by the * attribute array. Returns null if nothing is found. @@ -662,14 +667,14 @@ public final class BridgeContext extends Context { attributes.put(i, null); } } - + if (outFrameworkFlag != null) { outFrameworkFlag[0] = true; } - + return attributes; } - + // if the name was not found in the framework resources, look in the project // resources arrayName = mProjectCallback.resolveResourceValue(attrs); @@ -697,7 +702,7 @@ public final class BridgeContext extends Context { /** * Searches for the attribute referenced by its internal id. - * + * * @param attr An attribute reference given to obtainStyledAttributes such as defStyle. * @return The unique name of the attribute, if found, e.g. "buttonStyle". Returns null * if nothing is found. @@ -707,12 +712,12 @@ public final class BridgeContext extends Context { if (info != null) { return info[0]; } - + info = mProjectCallback.resolveResourceValue(attr); if (info != null) { return info[0]; } - + return null; } @@ -722,27 +727,27 @@ public final class BridgeContext extends Context { mDynamicIdToStyleMap = new HashMap<Integer, IStyleResourceValue>(); mStyleToDynamicIdMap = new HashMap<IStyleResourceValue, Integer>(); } - + // look for an existing id Integer id = mStyleToDynamicIdMap.get(resValue); - + if (id == null) { // generate a new id id = Integer.valueOf(++mDynamicIdGenerator); - + // and add it to the maps. mDynamicIdToStyleMap.put(id, resValue); mStyleToDynamicIdMap.put(resValue, id); } - + return id; } - + private IStyleResourceValue getStyleByDynamicId(int i) { if (mDynamicIdToStyleMap != null) { return mDynamicIdToStyleMap.get(i); } - + return null; } @@ -751,10 +756,10 @@ public final class BridgeContext extends Context { if (value != null) { return value.intValue(); } - + return defValue; } - + int getProjectIdValue(String idName, int defValue) { if (mProjectCallback != null) { Integer value = mProjectCallback.getResourceValue(BridgeConstants.RES_ID, idName); @@ -762,7 +767,7 @@ public final class BridgeContext extends Context { return value.intValue(); } } - + return defValue; } @@ -820,7 +825,7 @@ public final class BridgeContext extends Context { @Override public void clearWallpaper() { // TODO Auto-generated method stub - + } @Override @@ -850,46 +855,46 @@ public final class BridgeContext extends Context { @Override public void enforceCallingOrSelfPermission(String arg0, String arg1) { // TODO Auto-generated method stub - + } @Override public void enforceCallingOrSelfUriPermission(Uri arg0, int arg1, String arg2) { // TODO Auto-generated method stub - + } @Override public void enforceCallingPermission(String arg0, String arg1) { // TODO Auto-generated method stub - + } @Override public void enforceCallingUriPermission(Uri arg0, int arg1, String arg2) { // TODO Auto-generated method stub - + } @Override public void enforcePermission(String arg0, int arg1, int arg2, String arg3) { // TODO Auto-generated method stub - + } @Override public void enforceUriPermission(Uri arg0, int arg1, int arg2, int arg3, String arg4) { // TODO Auto-generated method stub - + } @Override public void enforceUriPermission(Uri arg0, String arg1, String arg2, int arg3, int arg4, int arg5, String arg6) { // TODO Auto-generated method stub - + } @Override @@ -965,7 +970,7 @@ public final class BridgeContext extends Context { // TODO Auto-generated method stub return null; } - + @Override public String getPackageResourcePath() { // TODO Auto-generated method stub @@ -1003,7 +1008,7 @@ public final class BridgeContext extends Context { @Override public void grantUriPermission(String arg0, Uri arg1, int arg2) { // TODO Auto-generated method stub - + } @SuppressWarnings("unused") @@ -1051,31 +1056,31 @@ public final class BridgeContext extends Context { @Override public void removeStickyBroadcast(Intent arg0) { // TODO Auto-generated method stub - + } @Override public void revokeUriPermission(Uri arg0, int arg1) { // TODO Auto-generated method stub - + } @Override public void sendBroadcast(Intent arg0) { // TODO Auto-generated method stub - + } @Override public void sendBroadcast(Intent arg0, String arg1) { // TODO Auto-generated method stub - + } @Override public void sendOrderedBroadcast(Intent arg0, String arg1) { // TODO Auto-generated method stub - + } @Override @@ -1083,39 +1088,39 @@ public final class BridgeContext extends Context { BroadcastReceiver arg2, Handler arg3, int arg4, String arg5, Bundle arg6) { // TODO Auto-generated method stub - + } @Override public void sendStickyBroadcast(Intent arg0) { // TODO Auto-generated method stub - + } @Override public void setTheme(int arg0) { // TODO Auto-generated method stub - + } @SuppressWarnings("unused") @Override public void setWallpaper(Bitmap arg0) throws IOException { // TODO Auto-generated method stub - + } @SuppressWarnings("unused") @Override public void setWallpaper(InputStream arg0) throws IOException { // TODO Auto-generated method stub - + } @Override public void startActivity(Intent arg0) { // TODO Auto-generated method stub - + } @Override @@ -1140,20 +1145,15 @@ public final class BridgeContext extends Context { @Override public void unbindService(ServiceConnection arg0) { // TODO Auto-generated method stub - + } @Override public void unregisterReceiver(BroadcastReceiver arg0) { // TODO Auto-generated method stub - - } - @Override - public Looper getMainLooper() { - throw new UnsupportedOperationException(); } - + @Override public Context getApplicationContext() { throw new UnsupportedOperationException(); diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeResources.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeResources.java index 0bcc7fd..8a040e4 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeResources.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeResources.java @@ -43,14 +43,14 @@ import java.io.FileReader; import java.io.InputStream; /** - * + * */ public final class BridgeResources extends Resources { private BridgeContext mContext; private IProjectCallback mProjectCallback; private boolean[] mPlatformResourceFlag = new boolean[1]; - + /** * This initializes the static field {@link Resources#mSystem} which is used * by methods who get global resources using {@link Resources#getSystem()}. @@ -59,7 +59,7 @@ public final class BridgeResources extends Resources { * <p/> * {@link Bridge} calls this method after setting up a new bridge. */ - /*package*/ static Resources initSystem(BridgeContext context, + /*package*/ static Resources initSystem(BridgeContext context, AssetManager assets, DisplayMetrics metrics, Configuration config, @@ -73,7 +73,7 @@ public final class BridgeResources extends Resources { } return Resources.mSystem; } - + /** * Clears the static {@link Resources#mSystem} to make sure we don't leave objects * around that would prevent us from unloading the library. @@ -92,15 +92,15 @@ public final class BridgeResources extends Resources { mContext = context; mProjectCallback = projectCallback; } - + public BridgeTypedArray newTypeArray(int numEntries, boolean platformFile) { return new BridgeTypedArray(this, mContext, numEntries, platformFile); } - + private IResourceValue getResourceValue(int id, boolean[] platformResFlag_out) { // first get the String related to this id in the framework String[] resourceInfo = Bridge.resolveResourceValue(id); - + if (resourceInfo != null) { platformResFlag_out[0] = true; return mContext.getFrameworkResource(resourceInfo[1], resourceInfo[0]); @@ -109,7 +109,7 @@ public final class BridgeResources extends Resources { // didn't find a match in the framework? look in the project. if (mProjectCallback != null) { resourceInfo = mProjectCallback.resolveResourceValue(id); - + if (resourceInfo != null) { platformResFlag_out[0] = false; return mContext.getProjectResource(resourceInfo[1], resourceInfo[0]); @@ -118,26 +118,26 @@ public final class BridgeResources extends Resources { return null; } - + @Override public Drawable getDrawable(int id) throws NotFoundException { IResourceValue value = getResourceValue(id, mPlatformResourceFlag); - + if (value != null) { return ResourceHelper.getDrawable(value.getValue(), mContext, value.isFramework()); } - + // id was not found or not resolved. Throw a NotFoundException. throwException(id); - + // this is not used since the method above always throws return null; } - + @Override public int getColor(int id) throws NotFoundException { IResourceValue value = getResourceValue(id, mPlatformResourceFlag); - + if (value != null) { try { return ResourceHelper.getColor(value.getValue()); @@ -145,18 +145,18 @@ public final class BridgeResources extends Resources { return 0; } } - + // id was not found or not resolved. Throw a NotFoundException. throwException(id); - + // this is not used since the method above always throws return 0; } - + @Override public ColorStateList getColorStateList(int id) throws NotFoundException { IResourceValue value = getResourceValue(id, mPlatformResourceFlag); - + if (value != null) { try { int color = ResourceHelper.getColor(value.getValue()); @@ -165,33 +165,33 @@ public final class BridgeResources extends Resources { return null; } } - + // id was not found or not resolved. Throw a NotFoundException. throwException(id); - + // this is not used since the method above always throws return null; } - + @Override public CharSequence getText(int id) throws NotFoundException { IResourceValue value = getResourceValue(id, mPlatformResourceFlag); - + if (value != null) { return value.getValue(); } - + // id was not found or not resolved. Throw a NotFoundException. throwException(id); - + // this is not used since the method above always throws return null; } - + @Override public XmlResourceParser getLayout(int id) throws NotFoundException { IResourceValue value = getResourceValue(id, mPlatformResourceFlag); - + if (value != null) { File xml = new File(value.getValue()); if (xml.isFile()) { @@ -201,7 +201,7 @@ public final class BridgeResources extends Resources { KXmlParser parser = new KXmlParser(); parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true); parser.setInput(new FileReader(xml)); - + return new BridgeXmlBlockParser(parser, mContext, mPlatformResourceFlag[0]); } catch (XmlPullParserException e) { mContext.getLogger().error(e); @@ -215,22 +215,22 @@ public final class BridgeResources extends Resources { // id was not found or not resolved. Throw a NotFoundException. throwException(id); - + // this is not used since the method above always throws return null; } - + @Override public TypedArray obtainAttributes(AttributeSet set, int[] attrs) { return mContext.obtainStyledAttributes(set, attrs); } - + @Override public TypedArray obtainTypedArray(int id) throws NotFoundException { throw new UnsupportedOperationException(); } - - + + @Override public float getDimension(int id) throws NotFoundException { IResourceValue value = getResourceValue(id, mPlatformResourceFlag); @@ -244,7 +244,7 @@ public final class BridgeResources extends Resources { } else if (v.equals(BridgeConstants.WRAP_CONTENT)) { return LayoutParams.WRAP_CONTENT; } - + if (ResourceHelper.stringToFloat(v, mTmpValue) && mTmpValue.type == TypedValue.TYPE_DIMENSION) { return mTmpValue.getDimension(mMetrics); @@ -254,7 +254,7 @@ public final class BridgeResources extends Resources { // id was not found or not resolved. Throw a NotFoundException. throwException(id); - + // this is not used since the method above always throws return 0; } @@ -276,7 +276,7 @@ public final class BridgeResources extends Resources { // id was not found or not resolved. Throw a NotFoundException. throwException(id); - + // this is not used since the method above always throws return 0; } @@ -298,7 +298,7 @@ public final class BridgeResources extends Resources { // id was not found or not resolved. Throw a NotFoundException. throwException(id); - + // this is not used since the method above always throws return 0; } @@ -306,7 +306,7 @@ public final class BridgeResources extends Resources { @Override public int getInteger(int id) throws NotFoundException { IResourceValue value = getResourceValue(id, mPlatformResourceFlag); - + if (value != null && value.getValue() != null) { String v = value.getValue(); int radix = 10; @@ -320,10 +320,10 @@ public final class BridgeResources extends Resources { // return exception below } } - + // id was not found or not resolved. Throw a NotFoundException. throwException(id); - + // this is not used since the method above always throws return 0; } @@ -348,12 +348,12 @@ public final class BridgeResources extends Resources { String s = getString(id); if (s != null) { return String.format(s, formatArgs); - + } // id was not found or not resolved. Throw a NotFoundException. throwException(id); - + // this is not used since the method above always throws return null; } @@ -361,14 +361,14 @@ public final class BridgeResources extends Resources { @Override public String getString(int id) throws NotFoundException { IResourceValue value = getResourceValue(id, mPlatformResourceFlag); - + if (value != null && value.getValue() != null) { return value.getValue(); } // id was not found or not resolved. Throw a NotFoundException. throwException(id); - + // this is not used since the method above always throws return null; } @@ -385,6 +385,11 @@ public final class BridgeResources extends Resources { if (ResourceHelper.stringToFloat(v, outValue)) { return; } + + // else it's a string + outValue.type = TypedValue.TYPE_STRING; + outValue.string = v; + return; } } @@ -413,7 +418,7 @@ public final class BridgeResources extends Resources { KXmlParser parser = new KXmlParser(); parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true); parser.setInput(new FileReader(f)); - + return new BridgeXmlBlockParser(parser, mContext, mPlatformResourceFlag[0]); } catch (XmlPullParserException e) { NotFoundException newE = new NotFoundException(); @@ -436,6 +441,33 @@ public final class BridgeResources extends Resources { } @Override + public XmlResourceParser loadXmlResourceParser(String file, int id, + int assetCookie, String type) throws NotFoundException { + // even though we know the XML file to load directly, we still need to resolve the + // id so that we can know if it's a platform or project resource. + // (mPlatformResouceFlag will get the result and will be used later). + getResourceValue(id, mPlatformResourceFlag); + + File f = new File(file); + try { + KXmlParser parser = new KXmlParser(); + parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true); + parser.setInput(new FileReader(f)); + + return new BridgeXmlBlockParser(parser, mContext, mPlatformResourceFlag[0]); + } catch (XmlPullParserException e) { + NotFoundException newE = new NotFoundException(); + newE.initCause(e); + throw newE; + } catch (FileNotFoundException e) { + NotFoundException newE = new NotFoundException(); + newE.initCause(e); + throw newE; + } + } + + + @Override public InputStream openRawResource(int id) throws NotFoundException { IResourceValue value = getResourceValue(id, mPlatformResourceFlag); @@ -482,7 +514,7 @@ public final class BridgeResources extends Resources { if (resourceInfo == null && mProjectCallback != null) { resourceInfo = mProjectCallback.resolveResourceValue(id); } - + String message = null; if (resourceInfo != null) { message = String.format( @@ -492,7 +524,7 @@ public final class BridgeResources extends Resources { message = String.format( "Could not resolve resource value: 0x%1$X.", id); } - + throw new NotFoundException(message); } } diff --git a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/Main.java b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/Main.java index 76bd8d4..c07baff 100644 --- a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/Main.java +++ b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/Main.java @@ -40,7 +40,7 @@ public class Main { for (String path : osJarPath) { log.info("Input : %1$s", path); } - + try { AsmGenerator agen = new AsmGenerator(log, osDestJar[0], new Class<?>[] { // classes to inject in the final JAR @@ -66,8 +66,10 @@ public class Main { "android.graphics.ComposeShader", "android.graphics._Original_ComposeShader", "android.graphics.RadialGradient", "android.graphics._Original_RadialGradient", "android.graphics.SweepGradient", "android.graphics._Original_SweepGradient", + "android.os.ServiceManager", "android.os._Original_ServiceManager", "android.util.FloatMath", "android.util._Original_FloatMath", "android.view.SurfaceView", "android.view._Original_SurfaceView", + "android.view.accessibility.AccessibilityManager", "android.view.accessibility._Original_AccessibilityManager", }, new String[] { // methods deleted from their return type. "android.graphics.Paint", // class to delete method from @@ -101,7 +103,7 @@ public class Main { }); aa.analyze(); agen.generate(); - + // Throw an error if any class failed to get renamed by the generator // // IMPORTANT: if you're building the platform and you get this error message, @@ -123,7 +125,7 @@ public class Main { } System.exit(1); } - + System.exit(0); } catch (IOException e) { log.exception(e, "Failed to load jar"); @@ -158,7 +160,7 @@ public class Main { return false; } } - + if (osJarPath.isEmpty()) { log.error("Missing parameter: path to input jar"); return false; |
