|
| 1 | +/*); |
| 2 | + * Copyright (C) 2012 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.systemui; |
| 18 | + |
| 19 | +import android.app.Activity; |
| 20 | +import android.content.Intent; |
| 21 | +import android.os.RemoteException; |
| 22 | +import android.os.ServiceManager; |
| 23 | +import android.service.dreams.IDreamManager; |
| 24 | +import android.util.Slog; |
| 25 | + |
| 26 | +public class Somnambulator extends Activity { |
| 27 | + |
| 28 | + public Somnambulator() { |
| 29 | + } |
| 30 | + |
| 31 | + @Override |
| 32 | + public void onStart() { |
| 33 | + super.onStart(); |
| 34 | + final Intent launchIntent = getIntent(); |
| 35 | + final String action = launchIntent.getAction(); |
| 36 | + if (Intent.ACTION_CREATE_SHORTCUT.equals(action)) { |
| 37 | + Intent shortcutIntent = new Intent(this, Somnambulator.class); |
| 38 | + shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS |
| 39 | + | Intent.FLAG_ACTIVITY_NEW_TASK); |
| 40 | + Intent resultIntent = new Intent(); |
| 41 | + resultIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, |
| 42 | + Intent.ShortcutIconResource.fromContext(this, R.mipmap.ic_dreams)); |
| 43 | + resultIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); |
| 44 | + resultIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.start_dreams)); |
| 45 | + setResult(RESULT_OK, resultIntent); |
| 46 | + } else { |
| 47 | + IDreamManager somnambulist = IDreamManager.Stub.asInterface( |
| 48 | + ServiceManager.checkService("dreams")); |
| 49 | + if (somnambulist != null) { |
| 50 | + try { |
| 51 | + Slog.v("Somnambulator", "Dreaming by user request."); |
| 52 | + somnambulist.dream(); |
| 53 | + } catch (RemoteException e) { |
| 54 | + // fine, stay asleep then |
| 55 | + } |
| 56 | + } |
| 57 | + } |
| 58 | + finish(); |
| 59 | + } |
| 60 | + |
| 61 | +} |
0 commit comments