Merge "Allow mode of TileService to be changed" into nyc-dev

am: aa336f8

* commit 'aa336f89265b8936d23e43189904de6ea9575538':
  Allow mode of TileService to be changed

Change-Id: Ia48acae4fb65f123755bc7c73b6d8204435f4d16
This commit is contained in:
Jason Monk
2016-04-09 00:41:23 +00:00
committed by android-build-merger
10 changed files with 43 additions and 80 deletions

View File

@@ -34813,7 +34813,7 @@ package android.service.quicksettings {
method public void onClick();
method public void onStartListening();
method public void onStopListening();
method public int onTileAdded();
method public void onTileAdded();
method public void onTileRemoved();
method public static final void requestListeningState(android.content.Context, android.content.ComponentName);
method public final void showDialog(android.app.Dialog);
@@ -34821,8 +34821,7 @@ package android.service.quicksettings {
method public final void unlockAndRun(java.lang.Runnable);
field public static final java.lang.String ACTION_QS_TILE = "android.service.quicksettings.action.QS_TILE";
field public static final java.lang.String ACTION_QS_TILE_PREFERENCES = "android.service.quicksettings.action.QS_TILE_PREFERENCES";
field public static final int TILE_MODE_ACTIVE = 2; // 0x2
field public static final int TILE_MODE_PASSIVE = 1; // 0x1
field public static final java.lang.String META_DATA_ACTIVE_TILE = "android.service.quicksettings.ACTIVE_TILE";
}
}

View File

@@ -37348,7 +37348,7 @@ package android.service.quicksettings {
method public void onClick();
method public void onStartListening();
method public void onStopListening();
method public int onTileAdded();
method public void onTileAdded();
method public void onTileRemoved();
method public static final void requestListeningState(android.content.Context, android.content.ComponentName);
method public final void setStatusIcon(android.graphics.drawable.Icon, java.lang.String);
@@ -37357,8 +37357,7 @@ package android.service.quicksettings {
method public final void unlockAndRun(java.lang.Runnable);
field public static final java.lang.String ACTION_QS_TILE = "android.service.quicksettings.action.QS_TILE";
field public static final java.lang.String ACTION_QS_TILE_PREFERENCES = "android.service.quicksettings.action.QS_TILE_PREFERENCES";
field public static final int TILE_MODE_ACTIVE = 2; // 0x2
field public static final int TILE_MODE_PASSIVE = 1; // 0x1
field public static final java.lang.String META_DATA_ACTIVE_TILE = "android.service.quicksettings.ACTIVE_TILE";
}
}

View File

@@ -34886,7 +34886,7 @@ package android.service.quicksettings {
method public void onClick();
method public void onStartListening();
method public void onStopListening();
method public int onTileAdded();
method public void onTileAdded();
method public void onTileRemoved();
method public static final void requestListeningState(android.content.Context, android.content.ComponentName);
method public final void showDialog(android.app.Dialog);
@@ -34894,8 +34894,7 @@ package android.service.quicksettings {
method public final void unlockAndRun(java.lang.Runnable);
field public static final java.lang.String ACTION_QS_TILE = "android.service.quicksettings.action.QS_TILE";
field public static final java.lang.String ACTION_QS_TILE_PREFERENCES = "android.service.quicksettings.action.QS_TILE_PREFERENCES";
field public static final int TILE_MODE_ACTIVE = 2; // 0x2
field public static final int TILE_MODE_PASSIVE = 1; // 0x1
field public static final java.lang.String META_DATA_ACTIVE_TILE = "android.service.quicksettings.ACTIVE_TILE";
}
}

View File

@@ -28,7 +28,6 @@ interface IQSService {
String contentDescription);
void onShowDialog(in Tile tile);
void onStartActivity(in Tile tile);
void setTileMode(in ComponentName component, int mode);
boolean isLocked();
boolean isSecure();
void startUnlockAndRun(in Tile tile);

View File

@@ -89,28 +89,24 @@ public class TileService extends Service {
public static final String ACTION_QS_TILE = "android.service.quicksettings.action.QS_TILE";
/**
* The tile mode hasn't been set yet.
* @hide
*/
public static final int TILE_MODE_UNSET = 0;
/**
* Constant to be returned by {@link #onTileAdded}.
* <p>
* Passive mode is the default mode for tiles. The System will tell the tile
* when it is most important to update by putting it in the listening state.
*/
public static final int TILE_MODE_PASSIVE = 1;
/**
* Constant to be returned by {@link #onTileAdded}.
* Meta-data for tile definition to set a tile into active mode.
* <p>
* Active mode is for tiles which already listen and keep track of their state in their
* own process. These tiles may request to send an update to the System while their process
* is alive using {@link #requestListeningState}. The System will only bind these tiles
* on its own when a click needs to occur.
*
* To make a TileService an active tile, set this meta-data to true on the TileService's
* manifest declaration.
* <pre class="prettyprint">
* {@literal
* <meta-data android:name="android.service.quicksettings.ACTIVE_TILE"
* android:value="true" />
* }
* </pre>
*/
public static final int TILE_MODE_ACTIVE = 2;
public static final String META_DATA_ACTIVE_TILE
= "android.service.quicksettings.ACTIVE_TILE";
/**
* Used to notify SysUI that Listening has be requested.
@@ -147,12 +143,8 @@ public class TileService extends Service {
* Note that this is not guaranteed to be called between {@link #onCreate()}
* and {@link #onStartListening()}, it will only be called when the tile is added
* and not on subsequent binds.
*
* @see #TILE_MODE_PASSIVE
* @see #TILE_MODE_ACTIVE
*/
public int onTileAdded() {
return TILE_MODE_PASSIVE;
public void onTileAdded() {
}
/**
@@ -386,15 +378,7 @@ public class TileService extends Service {
}
break;
case MSG_TILE_ADDED:
int mode = TileService.this.onTileAdded();
if (mService == null) {
return;
}
try {
mService.setTileMode(new ComponentName(TileService.this,
TileService.this.getClass()), mode);
} catch (RemoteException e) {
}
TileService.this.onTileAdded();
break;
case MSG_TILE_REMOVED:
if (mListening) {
@@ -431,8 +415,8 @@ public class TileService extends Service {
/**
* Requests that a tile be put in the listening state so it can send an update.
*
* This method is only applicable to tiles that return {@link #TILE_MODE_ACTIVE} from
* {@link #onTileAdded()}, and will do nothing otherwise.
* This method is only applicable to tiles that have {@link #META_DATA_ACTIVE_TILE} defined
* as true on their TileService Manifest declaration, and will do nothing otherwise.
*/
public static final void requestListeningState(Context context, ComponentName component) {
Intent intent = new Intent(ACTION_REQUEST_LISTENING);

View File

@@ -138,7 +138,7 @@ public class CustomTile extends QSTile<QSTile.State> {
mListening = listening;
try {
if (listening) {
if (mServiceManager.getType() == TileService.TILE_MODE_PASSIVE) {
if (!mServiceManager.isActiveTile()) {
mServiceManager.setBindRequested(true);
mService.onStartListening();
}
@@ -209,7 +209,7 @@ public class CustomTile extends QSTile<QSTile.State> {
} catch (RemoteException e) {
}
try {
if (mServiceManager.getType() == TileService.TILE_MODE_ACTIVE) {
if (mServiceManager.isActiveTile()) {
mServiceManager.setBindRequested(true);
mService.onStartListening();
}

View File

@@ -15,8 +15,6 @@
*/
package com.android.systemui.qs.external;
import libcore.util.Objects;
import android.app.AppGlobals;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
@@ -25,6 +23,7 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ServiceInfo;
import android.net.Uri;
import android.os.Handler;
@@ -34,9 +33,11 @@ import android.os.UserHandle;
import android.service.quicksettings.IQSService;
import android.service.quicksettings.IQSTileService;
import android.service.quicksettings.Tile;
import android.service.quicksettings.TileService;
import android.support.annotation.VisibleForTesting;
import android.util.ArraySet;
import android.util.Log;
import libcore.util.Objects;
import java.util.Set;
@@ -98,6 +99,17 @@ public class TileLifecycleManager extends BroadcastReceiver implements
}
}
public boolean isActiveTile() {
try {
ServiceInfo info = mContext.getPackageManager().getServiceInfo(mIntent.getComponent(),
PackageManager.MATCH_UNINSTALLED_PACKAGES | PackageManager.GET_META_DATA);
return info.metaData != null
&& info.metaData.getBoolean(TileService.META_DATA_ACTIVE_TILE, false);
} catch (NameNotFoundException e) {
return false;
}
}
/**
* Binds just long enough to send any queued messages, then unbinds.
*/

View File

@@ -21,7 +21,6 @@ import android.content.Intent;
import android.os.Handler;
import android.os.UserHandle;
import android.service.quicksettings.IQSTileService;
import android.service.quicksettings.TileService;
import android.support.annotation.VisibleForTesting;
import android.util.Log;
@@ -51,7 +50,6 @@ public class TileServiceManager {
private int mPriority;
private boolean mJustBound;
private long mLastUpdate;
private int mType;
private boolean mShowingDialog;
// Whether we have a pending bind going out to the service without a response yet.
// This defaults to true to ensure tiles start out unavailable.
@@ -69,25 +67,11 @@ public class TileServiceManager {
mServices = tileServices;
mHandler = handler;
mStateManager = tileLifecycleManager;
mType = tileServices.getContext().getSharedPreferences(PREFS_FILE, 0)
.getInt(tileLifecycleManager.getComponent().flattenToString(),
TileService.TILE_MODE_UNSET);
mStateManager.setQSService(tileServices);
if (mType == TileService.TILE_MODE_UNSET) {
bindService();
mStateManager.onTileAdded();
}
}
public int getType() {
return mType;
}
public void setType(int type) {
mServices.getContext().getSharedPreferences(PREFS_FILE, 0).edit()
.putInt(mStateManager.getComponent().flattenToString(), type).commit();
mType = type;
mServices.recalculateBindAllowance();
public boolean isActiveTile() {
return mStateManager.isActiveTile();
}
public void setShowingDialog(boolean dialog) {
@@ -114,7 +98,7 @@ public class TileServiceManager {
public void setLastUpdate(long lastUpdate) {
mLastUpdate = lastUpdate;
if (mBound && mType == TileService.TILE_MODE_ACTIVE) {
if (mBound && isActiveTile()) {
mStateManager.onStopListening();
setBindRequested(false);
}

View File

@@ -153,7 +153,7 @@ public class TileServices extends IQSService.Stub {
return;
}
TileServiceManager service = mServices.get(customTile);
if (service.getType() != TileService.TILE_MODE_ACTIVE) {
if (!service.isActiveTile()) {
return;
}
service.setBindRequested(true);
@@ -164,17 +164,6 @@ public class TileServices extends IQSService.Stub {
}
}
@Override
public void setTileMode(ComponentName component, int mode) {
verifyCaller(component.getPackageName());
CustomTile customTile = getTileForComponent(component);
if (customTile != null) {
synchronized (mServices) {
mServices.get(customTile).setType(mode);
}
}
}
@Override
public void updateQsTile(Tile tile) {
ComponentName componentName = tile.getComponentName();

View File

@@ -18,7 +18,6 @@ package com.android.systemui.qs.external;
import android.content.ComponentName;
import android.os.Handler;
import android.os.HandlerThread;
import android.service.quicksettings.TileService;
import android.test.suitebuilder.annotation.SmallTest;
import com.android.systemui.SysuiTestCase;
import org.mockito.ArgumentCaptor;
@@ -42,11 +41,10 @@ public class TileServiceManagerTests extends SysuiTestCase {
mTileServices = Mockito.mock(TileServices.class);
Mockito.when(mTileServices.getContext()).thenReturn(mContext);
mTileLifecycle = Mockito.mock(TileLifecycleManager.class);
Mockito.when(mTileLifecycle.isActiveTile()).thenReturn(false);
ComponentName componentName = new ComponentName(mContext,
TileServiceManagerTests.class);
Mockito.when(mTileLifecycle.getComponent()).thenReturn(componentName);
mContext.getSharedPreferences(TileServiceManager.PREFS_FILE, 0).edit()
.putInt(componentName.flattenToString(), TileService.TILE_MODE_PASSIVE).commit();
mTileServiceManager = new TileServiceManager(mTileServices, mHandler, mTileLifecycle);
}