/**
* Copyright (C) 2012 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.service.dreams;
import java.io.FileDescriptor;
import java.io.PrintWriter;
import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
import android.app.AlarmManager;
import android.app.Service;
import android.content.Intent;
import android.graphics.PixelFormat;
import android.graphics.drawable.ColorDrawable;
import android.os.Handler;
import android.os.IBinder;
import android.os.PowerManager;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.util.Slog;
import android.view.ActionMode;
import android.view.Display;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.view.WindowManagerGlobal;
import android.view.WindowManager.LayoutParams;
import android.view.accessibility.AccessibilityEvent;
import android.util.MathUtils;
import com.android.internal.policy.PolicyManager;
import com.android.internal.util.DumpUtils;
import com.android.internal.util.DumpUtils.Dump;
/**
* Extend this class to implement a custom dream (available to the user as a "Daydream").
*
* <p>Dreams are interactive screensavers launched when a charging device is idle, or docked in a
* desk dock. Dreams provide another modality for apps to express themselves, tailored for
* an exhibition/lean-back experience.</p>
*
* <p>The {@code DreamService} lifecycle is as follows:</p>
* <ol>
* <li>{@link #onAttachedToWindow}
* <p>Use this for initial setup, such as calling {@link #setContentView setContentView()}.</li>
* <li>{@link #onDreamingStarted}
* <p>Your dream has started, so you should begin animations or other behaviors here.</li>
* <li>{@link #onDreamingStopped}
* <p>Use this to stop the things you started in {@link #onDreamingStarted}.</li>
* <li>{@link #onDetachedFromWindow}
* <p>Use this to dismantle resources (for example, detach from handlers
* and listeners).</li>
* </ol>
*
* <p>In addition, onCreate and onDestroy (from the Service interface) will also be called, but
* initialization and teardown should be done by overriding the hooks above.</p>
*
* <p>To be available to the system, your {@code DreamService} should be declared in the
* manifest as follows:</p>
* <pre>
* <service
* android:name=".MyDream"
* android:exported="true"
* android:icon="@drawable/my_icon"
* android:label="@string/my_dream_label" >
*
* <intent-filter>
* <action android:name="android.service.dreams.DreamService" />
* <category android:name="android.intent.category.DEFAULT" />
* </intent-filter>
*
* <!-- Point to additional information for this dream (optional) -->
* <meta-data
* android:name="android.service.dream"
* android:resource="@xml/my_dream" />
* </service>
* </pre>
*
* <p>If specified with the {@code <meta-data>} element,
* additional information for the dream is defined using the
* {@link android.R.styleable#Dream <dream>} element in a separate XML file.
* Currently, the only addtional
* information you can provide is for a settings activity that allows the user to configure
* the dream behavior. For example:</p>
* <p class="code-caption">res/xml/my_dream.xml</p>
* <pre>
* <dream xmlns:android="http://schemas.android.com/apk/res/android"
* android:settingsActivity="com.example.app/.MyDreamSettingsActivity" />
* </pre>
* <p>This makes a Settings button available alongside your dream's listing in the
* system settings, which when pressed opens the specified activity.</p>
*
*
* <p>To specify your dream layout, call {@link #setContentView}, typically during the
* {@link #onAttachedToWindow} callback. For example:</p>
* <pre>
* public class MyDream extends DreamService {
*
* @Override
* public void onAttachedToWindow() {
* super.onAttachedToWindow();
*
* // Exit dream upon user touch
* setInteractive(false);
* // Hide system UI
* setFullscreen(true);
* // Set the dream layout
* setContentView(R.layout.dream);
* }
* }
* </pre>
*
* <p>When targeting api level 21 and above, you must declare the service in your manifest file
* with the {@link android.Manifest.permission#BIND_DREAM_SERVICE} permission. For example:</p>
* <pre>
* <service
* android:name=".MyDream"
* android:exported="true"
* android:icon="@drawable/my_icon"
* android:label="@string/my_dream_label"
* android:permission="android.permission.BIND_DREAM_SERVICE">
* <intent-filter>
* <action android:name=â |