| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.service.dreams; |
| 18 |
|
| 19 |
import android.annotation.NonNull; |
| 20 |
import android.annotation.Nullable; |
| 21 |
import android.annotation.TestApi; |
| 22 |
import android.app.Service; |
| 23 |
import android.content.ComponentName; |
| 24 |
import android.content.Intent; |
| 25 |
import android.os.IBinder; |
| 26 |
import android.os.RemoteException; |
| 27 |
import android.util.Log; |
| 28 |
import android.view.WindowManager; |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
@TestApi |
| 36 |
public abstract class DreamOverlayService extends Service { |
| 37 |
private static final String TAG = "DreamOverlayService"; |
| 38 |
private static final boolean DEBUG = false; |
| 39 |
private boolean mShowComplications; |
| 40 |
private ComponentName mDreamComponent; |
| 41 |
|
| 42 |
private IDreamOverlay mDreamOverlay = new IDreamOverlay.Stub() { |
| 43 |
@Override |
| 44 |
public void startDream(WindowManager.LayoutParams layoutParams, |
| 45 |
IDreamOverlayCallback callback, String dreamComponent, |
| 46 |
boolean shouldShowComplications) { |
| 47 |
mDreamOverlayCallback = callback; |
| 48 |
mDreamComponent = ComponentName.unflattenFromString(dreamComponent); |
| 49 |
mShowComplications = shouldShowComplications; |
| 50 |
onStartDream(layoutParams); |
| 51 |
} |
| 52 |
|
| 53 |
@Override |
| 54 |
public void wakeUp() { |
| 55 |
onWakeUp(() -> { |
| 56 |
try { |
| 57 |
mDreamOverlayCallback.onWakeUpComplete(); |
| 58 |
} catch (RemoteException e) { |
| 59 |
Log.e(TAG, "Could not notify dream of wakeUp:" + e); |
| 60 |
} |
| 61 |
}); |
| 62 |
} |
| 63 |
}; |
| 64 |
|
| 65 |
IDreamOverlayCallback mDreamOverlayCallback; |
| 66 |
|
| 67 |
public DreamOverlayService() { |
| 68 |
} |
| 69 |
|
| 70 |
@Nullable |
| 71 |
@Override |
| 72 |
public final IBinder onBind(@NonNull Intent intent) { |
| 73 |
return mDreamOverlay.asBinder(); |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
public abstract void onStartDream(@NonNull WindowManager.LayoutParams layoutParams); |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
public void onWakeUp(@NonNull Runnable onCompleteCallback) { |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
public final void requestExit() { |
| 99 |
try { |
| 100 |
mDreamOverlayCallback.onExitRequested(); |
| 101 |
} catch (RemoteException e) { |
| 102 |
Log.e(TAG, "Could not request exit:" + e); |
| 103 |
} |
| 104 |
} |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
public final boolean shouldShowComplications() { |
| 110 |
return mShowComplications; |
| 111 |
} |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
public final ComponentName getDreamComponent() { |
| 118 |
return mDreamComponent; |
| 119 |
} |
| 120 |
} |