M7350v1_en_gpl

This commit is contained in:
T
2024-09-09 08:52:07 +00:00
commit f9cc65cfda
65988 changed files with 26357421 additions and 0 deletions
@@ -0,0 +1,96 @@
/*
* Copyright (C) 2008 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 com.android.systemui.statusbar;
import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.Slog;
import android.view.View;
import android.widget.ImageView;
import android.widget.RemoteViews.RemoteView;
@RemoteView
public class AnimatedImageView extends ImageView {
AnimationDrawable mAnim;
boolean mAttached;
public AnimatedImageView(Context context) {
super(context);
}
public AnimatedImageView(Context context, AttributeSet attrs) {
super(context, attrs);
}
private void updateAnim() {
Drawable drawable = getDrawable();
if (mAttached && mAnim != null) {
mAnim.stop();
}
if (drawable instanceof AnimationDrawable) {
mAnim = (AnimationDrawable)drawable;
if (isShown()) {
mAnim.start();
}
} else {
mAnim = null;
}
}
@Override
public void setImageDrawable(Drawable drawable) {
super.setImageDrawable(drawable);
updateAnim();
}
@Override
@android.view.RemotableViewMethod
public void setImageResource(int resid) {
super.setImageResource(resid);
updateAnim();
}
@Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
mAttached = true;
}
@Override
public void onDetachedFromWindow() {
super.onDetachedFromWindow();
if (mAnim != null) {
mAnim.stop();
}
mAttached = false;
}
@Override
protected void onVisibilityChanged(View changedView, int vis) {
super.onVisibilityChanged(changedView, vis);
if (mAnim != null) {
if (isShown()) {
mAnim.start();
} else {
mAnim.stop();
}
}
}
}
@@ -0,0 +1,117 @@
/*
* Copyright (C) 2006 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 com.android.systemui.statusbar;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.provider.Telephony;
import android.util.AttributeSet;
import android.util.Slog;
import android.view.View;
import android.widget.TextView;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.TimeZone;
import com.android.internal.R;
/**
* This widget display an analogic clock with two hands for hours and
* minutes.
*/
public class CarrierLabel extends TextView {
private boolean mAttached;
public CarrierLabel(Context context) {
this(context, null);
}
public CarrierLabel(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public CarrierLabel(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
updateNetworkName(false, null, false, null);
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
if (!mAttached) {
mAttached = true;
IntentFilter filter = new IntentFilter();
filter.addAction(Telephony.Intents.SPN_STRINGS_UPDATED_ACTION);
getContext().registerReceiver(mIntentReceiver, filter, null, getHandler());
}
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
if (mAttached) {
getContext().unregisterReceiver(mIntentReceiver);
mAttached = false;
}
}
private final BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (Telephony.Intents.SPN_STRINGS_UPDATED_ACTION.equals(action)) {
updateNetworkName(intent.getBooleanExtra(Telephony.Intents.EXTRA_SHOW_SPN, false),
intent.getStringExtra(Telephony.Intents.EXTRA_SPN),
intent.getBooleanExtra(Telephony.Intents.EXTRA_SHOW_PLMN, false),
intent.getStringExtra(Telephony.Intents.EXTRA_PLMN));
}
}
};
void updateNetworkName(boolean showSpn, String spn, boolean showPlmn, String plmn) {
if (false) {
Slog.d("CarrierLabel", "updateNetworkName showSpn=" + showSpn + " spn=" + spn
+ " showPlmn=" + showPlmn + " plmn=" + plmn);
}
StringBuilder str = new StringBuilder();
boolean something = false;
if (showPlmn && plmn != null) {
str.append(plmn);
something = true;
}
if (showSpn && spn != null) {
if (something) {
str.append('\n');
}
str.append(spn);
something = true;
}
if (something) {
setText(str.toString());
} else {
setText(com.android.internal.R.string.lockscreen_carrier_default);
}
}
}
@@ -0,0 +1,208 @@
/*
* Copyright (C) 2006 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 com.android.systemui.statusbar;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.format.DateFormat;
import android.text.style.CharacterStyle;
import android.text.style.ForegroundColorSpan;
import android.text.style.RelativeSizeSpan;
import android.text.style.RelativeSizeSpan;
import android.text.style.StyleSpan;
import android.util.AttributeSet;
import android.view.View;
import android.widget.TextView;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.TimeZone;
import com.android.internal.R;
/**
* This widget display an analogic clock with two hands for hours and
* minutes.
*/
public class Clock extends TextView {
private boolean mAttached;
private Calendar mCalendar;
private String mClockFormatString;
private SimpleDateFormat mClockFormat;
private static final int AM_PM_STYLE_NORMAL = 0;
private static final int AM_PM_STYLE_SMALL = 1;
private static final int AM_PM_STYLE_GONE = 2;
private static final int AM_PM_STYLE = AM_PM_STYLE_GONE;
public Clock(Context context) {
this(context, null);
}
public Clock(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public Clock(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
if (!mAttached) {
mAttached = true;
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_TIME_TICK);
filter.addAction(Intent.ACTION_TIME_CHANGED);
filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
filter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
getContext().registerReceiver(mIntentReceiver, filter, null, getHandler());
}
// NOTE: It's safe to do these after registering the receiver since the receiver always runs
// in the main thread, therefore the receiver can't run before this method returns.
// The time zone may have changed while the receiver wasn't registered, so update the Time
mCalendar = Calendar.getInstance(TimeZone.getDefault());
// Make sure we update to the current time
updateClock();
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
if (mAttached) {
getContext().unregisterReceiver(mIntentReceiver);
mAttached = false;
}
}
private final BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action.equals(Intent.ACTION_TIMEZONE_CHANGED)) {
String tz = intent.getStringExtra("time-zone");
mCalendar = Calendar.getInstance(TimeZone.getTimeZone(tz));
if (mClockFormat != null) {
mClockFormat.setTimeZone(mCalendar.getTimeZone());
}
}
updateClock();
}
};
final void updateClock() {
mCalendar.setTimeInMillis(System.currentTimeMillis());
setText(getSmallTime());
}
private final CharSequence getSmallTime() {
Context context = getContext();
boolean b24 = DateFormat.is24HourFormat(context);
int res;
if (b24) {
res = R.string.twenty_four_hour_time_format;
} else {
res = R.string.twelve_hour_time_format;
}
final char MAGIC1 = '\uEF00';
final char MAGIC2 = '\uEF01';
SimpleDateFormat sdf;
String format = context.getString(res);
if (!format.equals(mClockFormatString)) {
/*
* Search for an unquoted "a" in the format string, so we can
* add dummy characters around it to let us find it again after
* formatting and change its size.
*/
if (AM_PM_STYLE != AM_PM_STYLE_NORMAL) {
int a = -1;
boolean quoted = false;
for (int i = 0; i < format.length(); i++) {
char c = format.charAt(i);
if (c == '\'') {
quoted = !quoted;
}
if (!quoted && c == 'a') {
a = i;
break;
}
}
if (a >= 0) {
// Move a back so any whitespace before AM/PM is also in the alternate size.
final int b = a;
while (a > 0 && Character.isWhitespace(format.charAt(a-1))) {
a--;
}
format = format.substring(0, a) + MAGIC1 + format.substring(a, b)
+ "a" + MAGIC2 + format.substring(b + 1);
}
}
mClockFormat = sdf = new SimpleDateFormat(format);
mClockFormatString = format;
} else {
sdf = mClockFormat;
}
String result = sdf.format(mCalendar.getTime());
if (AM_PM_STYLE != AM_PM_STYLE_NORMAL) {
int magic1 = result.indexOf(MAGIC1);
int magic2 = result.indexOf(MAGIC2);
if (magic1 >= 0 && magic2 > magic1) {
SpannableStringBuilder formatted = new SpannableStringBuilder(result);
if (AM_PM_STYLE == AM_PM_STYLE_GONE) {
formatted.delete(magic1, magic2+1);
} else {
if (AM_PM_STYLE == AM_PM_STYLE_SMALL) {
CharacterStyle style = new RelativeSizeSpan(0.7f);
formatted.setSpan(style, magic1, magic2,
Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
}
formatted.delete(magic2, magic2 + 1);
formatted.delete(magic1, magic1 + 1);
}
return formatted;
}
}
return result;
}
}
@@ -0,0 +1,51 @@
/*
* Copyright (C) 2008 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 com.android.systemui.statusbar;
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.LinearLayout;
public class CloseDragHandle extends LinearLayout {
StatusBarService mService;
public CloseDragHandle(Context context, AttributeSet attrs) {
super(context, attrs);
}
/**
* Ensure that, if there is no target under us to receive the touch,
* that we process it ourself. This makes sure that onInterceptTouchEvent()
* is always called for the entire gesture.
*/
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() != MotionEvent.ACTION_DOWN) {
mService.interceptTouchEvent(event);
}
return true;
}
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
return mService.interceptTouchEvent(event)
? true : super.onInterceptTouchEvent(event);
}
}
@@ -0,0 +1,203 @@
/*
* Copyright (C) 2010 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 com.android.systemui.statusbar;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import com.android.internal.statusbar.IStatusBar;
import com.android.internal.statusbar.StatusBarIcon;
import com.android.internal.statusbar.StatusBarIconList;
import com.android.internal.statusbar.StatusBarNotification;
/**
* This class takes the functions from IStatusBar that come in on
* binder pool threads and posts messages to get them onto the main
* thread, and calls onto Callbacks. It also takes care of
* coalescing these calls so they don't stack up. For the calls
* are coalesced, note that they are all idempotent.
*/
class CommandQueue extends IStatusBar.Stub {
private static final String TAG = "StatusBar.CommandQueue";
private static final int MSG_MASK = 0xffff0000;
private static final int INDEX_MASK = 0x0000ffff;
private static final int MSG_ICON = 0x00010000;
private static final int OP_SET_ICON = 1;
private static final int OP_REMOVE_ICON = 2;
private static final int MSG_ADD_NOTIFICATION = 0x00020000;
private static final int MSG_UPDATE_NOTIFICATION = 0x00030000;
private static final int MSG_REMOVE_NOTIFICATION = 0x00040000;
private static final int MSG_DISABLE = 0x00050000;
private static final int MSG_SET_VISIBILITY = 0x00060000;
private static final int OP_EXPAND = 1;
private static final int OP_COLLAPSE = 2;
private StatusBarIconList mList;
private Callbacks mCallbacks;
private Handler mHandler = new H();
private class NotificationQueueEntry {
IBinder key;
StatusBarNotification notification;
}
/**
* These methods are called back on the main thread.
*/
public interface Callbacks {
public void addIcon(String slot, int index, int viewIndex, StatusBarIcon icon);
public void updateIcon(String slot, int index, int viewIndex,
StatusBarIcon old, StatusBarIcon icon);
public void removeIcon(String slot, int index, int viewIndex);
public void addNotification(IBinder key, StatusBarNotification notification);
public void updateNotification(IBinder key, StatusBarNotification notification);
public void removeNotification(IBinder key);
public void disable(int state);
public void animateExpand();
public void animateCollapse();
}
public CommandQueue(Callbacks callbacks, StatusBarIconList list) {
mCallbacks = callbacks;
mList = list;
}
public void setIcon(int index, StatusBarIcon icon) {
synchronized (mList) {
int what = MSG_ICON | index;
mHandler.removeMessages(what);
mHandler.obtainMessage(what, OP_SET_ICON, 0, icon.clone()).sendToTarget();
}
}
public void removeIcon(int index) {
synchronized (mList) {
int what = MSG_ICON | index;
mHandler.removeMessages(what);
mHandler.obtainMessage(what, OP_REMOVE_ICON, 0, null).sendToTarget();
}
}
public void addNotification(IBinder key, StatusBarNotification notification) {
synchronized (mList) {
NotificationQueueEntry ne = new NotificationQueueEntry();
ne.key = key;
ne.notification = notification;
mHandler.obtainMessage(MSG_ADD_NOTIFICATION, 0, 0, ne).sendToTarget();
}
}
public void updateNotification(IBinder key, StatusBarNotification notification) {
synchronized (mList) {
NotificationQueueEntry ne = new NotificationQueueEntry();
ne.key = key;
ne.notification = notification;
mHandler.obtainMessage(MSG_UPDATE_NOTIFICATION, 0, 0, ne).sendToTarget();
}
}
public void removeNotification(IBinder key) {
synchronized (mList) {
mHandler.obtainMessage(MSG_REMOVE_NOTIFICATION, 0, 0, key).sendToTarget();
}
}
public void disable(int state) {
synchronized (mList) {
mHandler.removeMessages(MSG_DISABLE);
mHandler.obtainMessage(MSG_DISABLE, state, 0, null).sendToTarget();
}
}
public void animateExpand() {
synchronized (mList) {
mHandler.removeMessages(MSG_SET_VISIBILITY);
mHandler.obtainMessage(MSG_SET_VISIBILITY, OP_EXPAND, 0, null).sendToTarget();
}
}
public void animateCollapse() {
synchronized (mList) {
mHandler.removeMessages(MSG_SET_VISIBILITY);
mHandler.obtainMessage(MSG_SET_VISIBILITY, OP_COLLAPSE, 0, null).sendToTarget();
}
}
private final class H extends Handler {
public void handleMessage(Message msg) {
final int what = msg.what & MSG_MASK;
switch (what) {
case MSG_ICON: {
final int index = msg.what & INDEX_MASK;
final int viewIndex = mList.getViewIndex(index);
switch (msg.arg1) {
case OP_SET_ICON: {
StatusBarIcon icon = (StatusBarIcon)msg.obj;
StatusBarIcon old = mList.getIcon(index);
if (old == null) {
mList.setIcon(index, icon);
mCallbacks.addIcon(mList.getSlot(index), index, viewIndex, icon);
} else {
mList.setIcon(index, icon);
mCallbacks.updateIcon(mList.getSlot(index), index, viewIndex,
old, icon);
}
break;
}
case OP_REMOVE_ICON:
if (mList.getIcon(index) != null) {
mList.removeIcon(index);
mCallbacks.removeIcon(mList.getSlot(index), index, viewIndex);
}
break;
}
break;
}
case MSG_ADD_NOTIFICATION: {
final NotificationQueueEntry ne = (NotificationQueueEntry)msg.obj;
mCallbacks.addNotification(ne.key, ne.notification);
break;
}
case MSG_UPDATE_NOTIFICATION: {
final NotificationQueueEntry ne = (NotificationQueueEntry)msg.obj;
mCallbacks.updateNotification(ne.key, ne.notification);
break;
}
case MSG_REMOVE_NOTIFICATION: {
mCallbacks.removeNotification((IBinder)msg.obj);
break;
}
case MSG_DISABLE:
mCallbacks.disable(msg.arg1);
break;
case MSG_SET_VISIBILITY:
if (msg.arg1 == OP_EXPAND) {
mCallbacks.animateExpand();
} else {
mCallbacks.animateCollapse();
}
}
}
}
}
@@ -0,0 +1,89 @@
/*
* Copyright (C) 2008 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 com.android.systemui.statusbar;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.util.AttributeSet;
import android.util.Slog;
import android.widget.TextView;
import android.view.MotionEvent;
import java.text.DateFormat;
import java.util.Date;
public final class DateView extends TextView {
private static final String TAG = "DateView";
private boolean mUpdating = false;
private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action.equals(Intent.ACTION_TIME_TICK)
|| action.equals(Intent.ACTION_TIMEZONE_CHANGED)) {
updateClock();
}
}
};
public DateView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
setUpdates(false);
}
@Override
protected int getSuggestedMinimumWidth() {
// makes the large background bitmap not force us to full width
return 0;
}
private final void updateClock() {
Date now = new Date();
setText(DateFormat.getDateInstance(DateFormat.LONG).format(now));
}
void setUpdates(boolean update) {
if (update != mUpdating) {
mUpdating = update;
if (update) {
// Register for Intent broadcasts for the clock and battery
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_TIME_TICK);
filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
mContext.registerReceiver(mIntentReceiver, filter, null, null);
updateClock();
} else {
mContext.unregisterReceiver(mIntentReceiver);
}
}
}
}
@@ -0,0 +1,59 @@
/*
* Copyright (C) 2008 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 com.android.systemui.statusbar;
import android.content.Context;
import android.util.AttributeSet;
import android.view.Display;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.util.Slog;
public class ExpandedView extends LinearLayout {
StatusBarService mService;
int mPrevHeight = -1;
public ExpandedView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
}
/** We want to shrink down to 0, and ignore the background. */
@Override
public int getSuggestedMinimumHeight() {
return 0;
}
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
int height = bottom - top;
if (height != mPrevHeight) {
//Slog.d(StatusBarService.TAG, "height changed old=" + mPrevHeight
// + " new=" + height);
mPrevHeight = height;
mService.updateExpandedViewPos(StatusBarService.EXPANDED_LEAVE_ALONE);
}
}
}
@@ -0,0 +1,66 @@
/*
* Copyright (C) 2008 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 com.android.systemui.statusbar;
import android.graphics.drawable.Drawable;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.Rect;
import android.util.Slog;
class FixedSizeDrawable extends Drawable {
Drawable mDrawable;
int mLeft;
int mTop;
int mRight;
int mBottom;
FixedSizeDrawable(Drawable that) {
mDrawable = that;
}
public void setFixedBounds(int l, int t, int r, int b) {
mLeft = l;
mTop = t;
mRight = r;
mBottom = b;
}
public void setBounds(Rect bounds) {
mDrawable.setBounds(mLeft, mTop, mRight, mBottom);
}
public void setBounds(int l, int t, int r, int b) {
mDrawable.setBounds(mLeft, mTop, mRight, mBottom);
}
public void draw(Canvas canvas) {
mDrawable.draw(canvas);
}
public int getOpacity() {
return mDrawable.getOpacity();
}
public void setAlpha(int alpha) {
mDrawable.setAlpha(alpha);
}
public void setColorFilter(ColorFilter cf) {
mDrawable.setColorFilter(cf);
}
}
@@ -0,0 +1,140 @@
/*
* Copyright (C) 2008 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 com.android.systemui.statusbar;
import android.content.Context;
import android.os.Handler;
import android.util.AttributeSet;
import android.util.Slog;
import android.view.View;
import android.widget.LinearLayout;
import com.android.internal.statusbar.StatusBarIcon;
import com.android.systemui.R;
public class IconMerger extends LinearLayout {
private static final String TAG = "IconMerger";
private int mIconSize;
private StatusBarIconView mMoreView;
private StatusBarIcon mMoreIcon = new StatusBarIcon(null, R.drawable.stat_notify_more, 0);
public IconMerger(Context context, AttributeSet attrs) {
super(context, attrs);
mIconSize = context.getResources().getDimensionPixelSize(
com.android.internal.R.dimen.status_bar_icon_size);
mMoreView = new StatusBarIconView(context, "more");
mMoreView.set(mMoreIcon);
addView(mMoreView, 0, new LinearLayout.LayoutParams(mIconSize, mIconSize));
}
public void addView(StatusBarIconView v, int index) {
if (index == 0) {
throw new RuntimeException("Attempt to put view before the more view: " + v);
}
addView(v, index, new LinearLayout.LayoutParams(mIconSize, mIconSize));
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed, l, t, r, b);
final int maxWidth = r - l;
final int N = getChildCount();
int i;
// get the rightmost one, and see if we even need to do anything
int fitRight = -1;
for (i=N-1; i>=0; i--) {
final View child = getChildAt(i);
if (child.getVisibility() != GONE) {
fitRight = child.getRight();
break;
}
}
// find the first visible one that isn't the more icon
final StatusBarIconView moreView = mMoreView;
int fitLeft = -1;
int startIndex = -1;
for (i=0; i<N; i++) {
final View child = getChildAt(i);
if (child == moreView) {
startIndex = i+1;
}
else if (child.getVisibility() != GONE) {
fitLeft = child.getLeft();
break;
}
}
if (moreView == null || startIndex < 0) {
return;
/*
throw new RuntimeException("Status Bar / IconMerger moreView == " + moreView
+ " startIndex=" + startIndex);
*/
}
// if it fits without the more icon, then hide the more icon and update fitLeft
// so everything gets pushed left
int adjust = 0;
if (fitRight - fitLeft <= maxWidth) {
adjust = fitLeft - moreView.getLeft();
fitLeft -= adjust;
fitRight -= adjust;
moreView.layout(0, moreView.getTop(), 0, moreView.getBottom());
}
int extra = fitRight - r;
int shift = -1;
int breakingPoint = fitLeft + extra + adjust;
int number = 0;
for (i=startIndex; i<N; i++) {
final StatusBarIconView child = (StatusBarIconView)getChildAt(i);
if (child.getVisibility() != GONE) {
int childLeft = child.getLeft();
int childRight = child.getRight();
if (childLeft < breakingPoint) {
// hide this one
child.layout(0, child.getTop(), 0, child.getBottom());
int n = child.getStatusBarIcon().number;
if (n == 0) {
number += 1;
} else if (n > 0) {
number += n;
}
} else {
// decide how much to shift by
if (shift < 0) {
shift = childLeft - fitLeft;
}
// shift this left by shift
child.layout(childLeft-shift, child.getTop(),
childRight-shift, child.getBottom());
}
}
}
mMoreIcon.number = number;
mMoreView.set(mMoreIcon);
}
}
@@ -0,0 +1,34 @@
/*
* Copyright (C) 2008 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 com.android.systemui.statusbar;
import android.content.Context;
import android.util.AttributeSet;
import android.util.Slog;
import android.view.MotionEvent;
import android.widget.FrameLayout;
public class LatestItemView extends FrameLayout {
public LatestItemView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public boolean dispatchTouchEvent(MotionEvent ev) {
return onTouchEvent(ev);
}
}
@@ -0,0 +1,126 @@
/*
* Copyright (C) 2008 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 com.android.systemui.statusbar;
import android.app.Notification;
import android.os.IBinder;
import android.view.View;
import com.android.internal.statusbar.StatusBarNotification;
import java.util.ArrayList;
/**
* The list of currently displaying notifications.
*/
public class NotificationData {
public static final class Entry {
public IBinder key;
public StatusBarNotification notification;
public StatusBarIconView icon;
public View row; // the outer expanded view
public View content; // takes the click events and sends the PendingIntent
public View expanded; // the inflated RemoteViews
}
private final ArrayList<Entry> mEntries = new ArrayList<Entry>();
public int size() {
return mEntries.size();
}
public Entry getEntryAt(int index) {
return mEntries.get(index);
}
public int findEntry(IBinder key) {
final int N = mEntries.size();
for (int i=0; i<N; i++) {
Entry entry = mEntries.get(i);
if (entry.key == key) {
return i;
}
}
return -1;
}
public int add(IBinder key, StatusBarNotification notification, View row, View content,
View expanded, StatusBarIconView icon) {
Entry entry = new Entry();
entry.key = key;
entry.notification = notification;
entry.row = row;
entry.content = content;
entry.expanded = expanded;
entry.icon = icon;
final int index = chooseIndex(notification.notification.when);
mEntries.add(index, entry);
return index;
}
public Entry remove(IBinder key) {
final int N = mEntries.size();
for (int i=0; i<N; i++) {
Entry entry = mEntries.get(i);
if (entry.key == key) {
mEntries.remove(i);
return entry;
}
}
return null;
}
private int chooseIndex(final long when) {
final int N = mEntries.size();
for (int i=0; i<N; i++) {
Entry entry = mEntries.get(i);
if (entry.notification.notification.when > when) {
return i;
}
}
return N;
}
/**
* Return whether there are any visible items (i.e. items without an error).
*/
public boolean hasVisibleItems() {
final int N = mEntries.size();
for (int i=0; i<N; i++) {
Entry entry = mEntries.get(i);
if (entry.expanded != null) { // the view successfully inflated
return true;
}
}
return false;
}
/**
* Return whether there are any clearable items (that aren't errors).
*/
public boolean hasClearableItems() {
final int N = mEntries.size();
for (int i=0; i<N; i++) {
Entry entry = mEntries.get(i);
if (entry.expanded != null) { // the view successfully inflated
if ((entry.notification.notification.flags & Notification.FLAG_NO_CLEAR) == 0) {
return true;
}
}
}
return false;
}
}
@@ -0,0 +1,29 @@
/*
* Copyright (C) 2008 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 com.android.systemui.statusbar;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.LinearLayout;
public class NotificationLinearLayout extends LinearLayout {
public NotificationLinearLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
}
@@ -0,0 +1,202 @@
/*
* Copyright (C) 2008 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 com.android.systemui.statusbar;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.util.Slog;
import android.util.Log;
import android.view.View;
import android.view.ViewDebug;
import android.widget.FrameLayout;
import com.android.internal.statusbar.StatusBarIcon;
import com.android.systemui.R;
public class StatusBarIconView extends AnimatedImageView {
private static final String TAG = "StatusBarIconView";
private StatusBarIcon mIcon;
@ViewDebug.ExportedProperty private String mSlot;
private Drawable mNumberBackground;
private Paint mNumberPain;
private int mNumberX;
private int mNumberY;
private String mNumberText;
public StatusBarIconView(Context context, String slot) {
super(context);
final Resources res = context.getResources();
mSlot = slot;
mNumberPain = new Paint();
mNumberPain.setTextAlign(Paint.Align.CENTER);
mNumberPain.setColor(res.getColor(R.drawable.notification_number_text_color));
mNumberPain.setAntiAlias(true);
}
private static boolean streq(String a, String b) {
if (a == b) {
return true;
}
if (a == null && b != null) {
return false;
}
if (a != null && b == null) {
return false;
}
return a.equals(b);
}
/**
* Returns whether the set succeeded.
*/
public boolean set(StatusBarIcon icon) {
final boolean iconEquals = mIcon != null
&& streq(mIcon.iconPackage, icon.iconPackage)
&& mIcon.iconId == icon.iconId;
final boolean levelEquals = iconEquals
&& mIcon.iconLevel == icon.iconLevel;
final boolean visibilityEquals = mIcon != null
&& mIcon.visible == icon.visible;
final boolean numberEquals = mIcon != null
&& mIcon.number == icon.number;
mIcon = icon.clone();
if (!iconEquals) {
Drawable drawable = getIcon(icon);
if (drawable == null) {
Slog.w(StatusBarService.TAG, "No icon for slot " + mSlot);
return false;
}
setImageDrawable(drawable);
}
if (!levelEquals) {
setImageLevel(icon.iconLevel);
}
if (!numberEquals) {
if (icon.number > 0) {
if (mNumberBackground == null) {
mNumberBackground = getContext().getResources().getDrawable(
R.drawable.ic_notification_overlay);
}
placeNumber();
} else {
mNumberBackground = null;
mNumberText = null;
}
invalidate();
}
if (!visibilityEquals) {
setVisibility(icon.visible ? VISIBLE : GONE);
}
return true;
}
private Drawable getIcon(StatusBarIcon icon) {
return getIcon(getContext(), icon);
}
/**
* Returns the right icon to use for this item, respecting the iconId and
* iconPackage (if set)
*
* @param context Context to use to get resources if iconPackage is not set
* @return Drawable for this item, or null if the package or item could not
* be found
*/
public static Drawable getIcon(Context context, StatusBarIcon icon) {
Resources r = null;
if (icon.iconPackage != null) {
try {
r = context.getPackageManager().getResourcesForApplication(icon.iconPackage);
} catch (PackageManager.NameNotFoundException ex) {
Slog.e(StatusBarService.TAG, "Icon package not found: " + icon.iconPackage);
return null;
}
} else {
r = context.getResources();
}
if (icon.iconId == 0) {
return null;
}
try {
return r.getDrawable(icon.iconId);
} catch (RuntimeException e) {
Slog.w(StatusBarService.TAG, "Icon not found in "
+ (icon.iconPackage != null ? icon.iconId : "<system>")
+ ": " + Integer.toHexString(icon.iconId));
}
return null;
}
public StatusBarIcon getStatusBarIcon() {
return mIcon;
}
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
if (mNumberBackground != null) {
placeNumber();
}
}
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (mNumberBackground != null) {
mNumberBackground.draw(canvas);
canvas.drawText(mNumberText, mNumberX, mNumberY, mNumberPain);
}
}
protected void debug(int depth) {
super.debug(depth);
Log.d("View", debugIndent(depth) + "slot=" + mSlot);
Log.d("View", debugIndent(depth) + "icon=" + mIcon);
}
void placeNumber() {
final String str = mNumberText = Integer.toString(mIcon.number);
final int w = getWidth();
final int h = getHeight();
final Rect r = new Rect();
mNumberPain.getTextBounds(str, 0, str.length(), r);
final int tw = r.right - r.left;
final int th = r.bottom - r.top;
mNumberBackground.getPadding(r);
int dw = r.left + tw + r.right;
if (dw < mNumberBackground.getMinimumWidth()) {
dw = mNumberBackground.getMinimumWidth();
}
mNumberX = w-r.right-((dw-r.right-r.left)/2);
int dh = r.top + th + r.bottom;
if (dh < mNumberBackground.getMinimumWidth()) {
dh = mNumberBackground.getMinimumWidth();
}
mNumberY = h-r.bottom-((dh-r.top-th-r.bottom)/2);
mNumberBackground.setBounds(w-dw, h-dh, w, h);
}
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,153 @@
/*
* Copyright (C) 2008 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 com.android.systemui.statusbar;
import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Canvas;
import android.os.SystemClock;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.FrameLayout;
import com.android.systemui.R;
public class StatusBarView extends FrameLayout {
private static final String TAG = "StatusBarView";
static final int DIM_ANIM_TIME = 400;
StatusBarService mService;
boolean mTracking;
int mStartX, mStartY;
ViewGroup mNotificationIcons;
ViewGroup mStatusIcons;
View mDate;
FixedSizeDrawable mBackground;
public StatusBarView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
mNotificationIcons = (ViewGroup)findViewById(R.id.notificationIcons);
mStatusIcons = (ViewGroup)findViewById(R.id.statusIcons);
mDate = findViewById(R.id.date);
mBackground = new FixedSizeDrawable(mDate.getBackground());
mBackground.setFixedBounds(0, 0, 0, 0);
mDate.setBackgroundDrawable(mBackground);
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
mService.onBarViewAttached();
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
mService.updateExpandedViewPos(StatusBarService.EXPANDED_LEAVE_ALONE);
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed, l, t, r, b);
// put the date date view quantized to the icons
int oldDateRight = mDate.getRight();
int newDateRight;
newDateRight = getDateSize(mNotificationIcons, oldDateRight,
getViewOffset(mNotificationIcons));
if (newDateRight < 0) {
int offset = getViewOffset(mStatusIcons);
if (oldDateRight < offset) {
newDateRight = oldDateRight;
} else {
newDateRight = getDateSize(mStatusIcons, oldDateRight, offset);
if (newDateRight < 0) {
newDateRight = r;
}
}
}
int max = r - getPaddingRight();
if (newDateRight > max) {
newDateRight = max;
}
mDate.layout(mDate.getLeft(), mDate.getTop(), newDateRight, mDate.getBottom());
mBackground.setFixedBounds(-mDate.getLeft(), -mDate.getTop(), (r-l), (b-t));
}
/**
* Gets the left position of v in this view. Throws if v is not
* a child of this.
*/
private int getViewOffset(View v) {
int offset = 0;
while (v != this) {
offset += v.getLeft();
ViewParent p = v.getParent();
if (v instanceof View) {
v = (View)p;
} else {
throw new RuntimeException(v + " is not a child of " + this);
}
}
return offset;
}
private int getDateSize(ViewGroup g, int w, int offset) {
final int N = g.getChildCount();
for (int i=0; i<N; i++) {
View v = g.getChildAt(i);
int l = v.getLeft() + offset;
int r = v.getRight() + offset;
if (w >= l && w <= r) {
return r;
}
}
return -1;
}
/**
* Ensure that, if there is no target under us to receive the touch,
* that we process it ourself. This makes sure that onInterceptTouchEvent()
* is always called for the entire gesture.
*/
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() != MotionEvent.ACTION_DOWN) {
mService.interceptTouchEvent(event);
}
return true;
}
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
return mService.interceptTouchEvent(event)
? true : super.onInterceptTouchEvent(event);
}
}
@@ -0,0 +1,273 @@
/*
* Copyright (C) 2008 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 com.android.systemui.statusbar;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.text.StaticLayout;
import android.text.Layout.Alignment;
import android.text.TextPaint;
import android.text.TextUtils;
import android.util.Slog;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.TextSwitcher;
import android.widget.TextView;
import android.widget.ImageSwitcher;
import java.util.ArrayList;
import com.android.internal.statusbar.StatusBarIcon;
import com.android.internal.statusbar.StatusBarNotification;
import com.android.internal.util.CharSequences;
import com.android.systemui.R;
public abstract class Ticker {
private static final int TICKER_SEGMENT_DELAY = 3000;
private Context mContext;
private Handler mHandler = new Handler();
private ArrayList<Segment> mSegments = new ArrayList();
private TextPaint mPaint;
private View mTickerView;
private ImageSwitcher mIconSwitcher;
private TextSwitcher mTextSwitcher;
private final class Segment {
StatusBarNotification notification;
Drawable icon;
CharSequence text;
int current;
int next;
boolean first;
StaticLayout getLayout(CharSequence substr) {
int w = mTextSwitcher.getWidth() - mTextSwitcher.getPaddingLeft()
- mTextSwitcher.getPaddingRight();
return new StaticLayout(substr, mPaint, w, Alignment.ALIGN_NORMAL, 1, 0, true);
}
CharSequence rtrim(CharSequence substr, int start, int end) {
while (end > start && !TextUtils.isGraphic(substr.charAt(end-1))) {
end--;
}
if (end > start) {
return substr.subSequence(start, end);
}
return null;
}
/** returns null if there is no more text */
CharSequence getText() {
if (this.current > this.text.length()) {
return null;
}
CharSequence substr = this.text.subSequence(this.current, this.text.length());
StaticLayout l = getLayout(substr);
int lineCount = l.getLineCount();
if (lineCount > 0) {
int start = l.getLineStart(0);
int end = l.getLineEnd(0);
this.next = this.current + end;
return rtrim(substr, start, end);
} else {
throw new RuntimeException("lineCount=" + lineCount + " current=" + current +
" text=" + text);
}
}
/** returns null if there is no more text */
CharSequence advance() {
this.first = false;
int index = this.next;
final int len = this.text.length();
while (index < len && !TextUtils.isGraphic(this.text.charAt(index))) {
index++;
}
if (index >= len) {
return null;
}
CharSequence substr = this.text.subSequence(index, this.text.length());
StaticLayout l = getLayout(substr);
final int lineCount = l.getLineCount();
int i;
for (i=0; i<lineCount; i++) {
int start = l.getLineStart(i);
int end = l.getLineEnd(i);
if (i == lineCount-1) {
this.next = len;
} else {
this.next = index + l.getLineStart(i+1);
}
CharSequence result = rtrim(substr, start, end);
if (result != null) {
this.current = index + start;
return result;
}
}
this.current = len;
return null;
}
Segment(StatusBarNotification n, Drawable icon, CharSequence text) {
this.notification = n;
this.icon = icon;
this.text = text;
int index = 0;
final int len = text.length();
while (index < len && !TextUtils.isGraphic(text.charAt(index))) {
index++;
}
this.current = index;
this.next = index;
this.first = true;
}
};
Ticker(Context context, StatusBarView sb) {
mContext = context;
mTickerView = sb.findViewById(R.id.ticker);
mIconSwitcher = (ImageSwitcher)sb.findViewById(R.id.tickerIcon);
mIconSwitcher.setInAnimation(
AnimationUtils.loadAnimation(context, com.android.internal.R.anim.push_up_in));
mIconSwitcher.setOutAnimation(
AnimationUtils.loadAnimation(context, com.android.internal.R.anim.push_up_out));
mTextSwitcher = (TextSwitcher)sb.findViewById(R.id.tickerText);
mTextSwitcher.setInAnimation(
AnimationUtils.loadAnimation(context, com.android.internal.R.anim.push_up_in));
mTextSwitcher.setOutAnimation(
AnimationUtils.loadAnimation(context, com.android.internal.R.anim.push_up_out));
// Copy the paint style of one of the TextSwitchers children to use later for measuring
TextView text = (TextView)mTextSwitcher.getChildAt(0);
mPaint = text.getPaint();
}
void addEntry(StatusBarNotification n) {
int initialCount = mSegments.size();
// If what's being displayed has the same text and icon, just drop it
// (which will let the current one finish, this happens when apps do
// a notification storm).
if (initialCount > 0) {
final Segment seg = mSegments.get(0);
if (n.pkg.equals(seg.notification.pkg)
&& n.notification.icon == seg.notification.notification.icon
&& n.notification.iconLevel == seg.notification.notification.iconLevel
&& CharSequences.equals(seg.notification.notification.tickerText,
n.notification.tickerText)) {
return;
}
}
final Drawable icon = StatusBarIconView.getIcon(mContext,
new StatusBarIcon(n.pkg, n.notification.icon, n.notification.iconLevel, 0));
final Segment newSegment = new Segment(n, icon, n.notification.tickerText);
// If there's already a notification schedule for this package and id, remove it.
for (int i=0; i<mSegments.size(); i++) {
Segment seg = mSegments.get(i);
if (n.id == seg.notification.id && n.pkg.equals(seg.notification.pkg)) {
// just update that one to use this new data instead
mSegments.remove(i--); // restart iteration here
}
}
mSegments.add(newSegment);
if (initialCount == 0 && mSegments.size() > 0) {
Segment seg = mSegments.get(0);
seg.first = false;
mIconSwitcher.setAnimateFirstView(false);
mIconSwitcher.reset();
mIconSwitcher.setImageDrawable(seg.icon);
mTextSwitcher.setAnimateFirstView(false);
mTextSwitcher.reset();
mTextSwitcher.setText(seg.getText());
tickerStarting();
scheduleAdvance();
}
}
void removeEntry(StatusBarNotification n) {
for (int i=mSegments.size()-1; i>=0; i--) {
Segment seg = mSegments.get(i);
if (n.id == seg.notification.id && n.pkg.equals(seg.notification.pkg)) {
mSegments.remove(i);
}
}
}
void halt() {
mHandler.removeCallbacks(mAdvanceTicker);
mSegments.clear();
tickerHalting();
}
void reflowText() {
if (mSegments.size() > 0) {
Segment seg = mSegments.get(0);
CharSequence text = seg.getText();
mTextSwitcher.setCurrentText(text);
}
}
private Runnable mAdvanceTicker = new Runnable() {
public void run() {
while (mSegments.size() > 0) {
Segment seg = mSegments.get(0);
if (seg.first) {
// this makes the icon slide in for the first one for a given
// notification even if there are two notifications with the
// same icon in a row
mIconSwitcher.setImageDrawable(seg.icon);
}
CharSequence text = seg.advance();
if (text == null) {
mSegments.remove(0);
continue;
}
mTextSwitcher.setText(text);
scheduleAdvance();
break;
}
if (mSegments.size() == 0) {
tickerDone();
}
}
};
private void scheduleAdvance() {
mHandler.postDelayed(mAdvanceTicker, TICKER_SEGMENT_DELAY);
}
abstract void tickerStarting();
abstract void tickerDone();
abstract void tickerHalting();
}
@@ -0,0 +1,38 @@
/*
* Copyright (C) 2008 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 com.android.systemui.statusbar;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.TextSwitcher;
public class TickerView extends TextSwitcher
{
Ticker mTicker;
public TickerView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
mTicker.reflowText();
}
}
@@ -0,0 +1,70 @@
/*
* Copyright (C) 2008 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 com.android.systemui.statusbar;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.util.Slog;
import android.view.View;
import android.graphics.BitmapFactory;
import android.graphics.Bitmap;
import android.graphics.Paint;
import android.graphics.Canvas;
public class TrackingPatternView extends View {
private Bitmap mTexture;
private Paint mPaint;
private int mTextureWidth;
private int mTextureHeight;
public TrackingPatternView(Context context, AttributeSet attrs) {
super(context, attrs);
mTexture = BitmapFactory.decodeResource(getResources(),
com.android.internal.R.drawable.status_bar_background);
mTextureWidth = mTexture.getWidth();
mTextureHeight = mTexture.getHeight();
mPaint = new Paint();
mPaint.setDither(false);
}
@Override
public void onDraw(Canvas canvas) {
final Bitmap texture = mTexture;
final Paint paint = mPaint;
final int width = getWidth();
final int height = getHeight();
final int textureWidth = mTextureWidth;
final int textureHeight = mTextureHeight;
int x = 0;
int y;
while (x < width) {
y = 0;
while (y < height) {
canvas.drawBitmap(texture, x, y, paint);
y += textureHeight;
}
x += textureWidth;
}
}
}
@@ -0,0 +1,63 @@
/*
* Copyright (C) 2008 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 com.android.systemui.statusbar;
import android.content.Context;
import android.util.AttributeSet;
import android.view.Display;
import android.view.KeyEvent;
import android.view.WindowManager;
import android.widget.LinearLayout;
public class TrackingView extends LinearLayout {
final Display mDisplay;
StatusBarService mService;
boolean mTracking;
int mStartX, mStartY;
public TrackingView(Context context, AttributeSet attrs) {
super(context, attrs);
mDisplay = ((WindowManager)context.getSystemService(
Context.WINDOW_SERVICE)).getDefaultDisplay();
}
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
mService.updateExpandedHeight();
}
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
switch (event.getKeyCode()) {
case KeyEvent.KEYCODE_BACK:
if (down) {
//mService.deactivate();
}
return true;
}
return super.dispatchKeyEvent(event);
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
mService.onTrackingViewAttached();
}
}
@@ -0,0 +1,415 @@
/*
* Copyright (C) 2010 Google Inc.
*
* 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 com.android.systemui.usb;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Environment;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.storage.StorageEventListener;
import android.os.storage.StorageManager;
import android.provider.Settings;
import android.util.Slog;
public class StorageNotification extends StorageEventListener {
private static final String TAG = "StorageNotification";
private static final boolean POP_UMS_ACTIVITY_ON_CONNECT = true;
/**
* Binder context for this service
*/
private Context mContext;
/**
* The notification that is shown when a USB mass storage host
* is connected.
* <p>
* This is lazily created, so use {@link #setUsbStorageNotification()}.
*/
private Notification mUsbStorageNotification;
/**
* The notification that is shown when the following media events occur:
* - Media is being checked
* - Media is blank (or unknown filesystem)
* - Media is corrupt
* - Media is safe to unmount
* - Media is missing
* <p>
* This is lazily created, so use {@link #setMediaStorageNotification()}.
*/
private Notification mMediaStorageNotification;
private boolean mUmsAvailable;
private StorageManager mStorageManager;
private Handler mAsyncEventHandler;
public StorageNotification(Context context) {
mContext = context;
mStorageManager = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE);
final boolean connected = mStorageManager.isUsbMassStorageConnected();
Slog.d(TAG, String.format( "Startup with UMS connection %s (media state %s)", mUmsAvailable,
Environment.getExternalStorageState()));
HandlerThread thr = new HandlerThread("SystemUI StorageNotification");
thr.start();
mAsyncEventHandler = new Handler(thr.getLooper());
onUsbMassStorageConnectionChanged(connected);
}
/*
* @override com.android.os.storage.StorageEventListener
*/
@Override
public void onUsbMassStorageConnectionChanged(final boolean connected) {
mAsyncEventHandler.post(new Runnable() {
@Override
public void run() {
onUsbMassStorageConnectionChangedAsync(connected);
}
});
}
private void onUsbMassStorageConnectionChangedAsync(boolean connected) {
mUmsAvailable = connected;
/*
* Even though we may have a UMS host connected, we the SD card
* may not be in a state for export.
*/
String st = Environment.getExternalStorageState();
Slog.i(TAG, String.format("UMS connection changed to %s (media state %s)", connected, st));
if (connected && (st.equals(
Environment.MEDIA_REMOVED) || st.equals(Environment.MEDIA_CHECKING))) {
/*
* No card or card being checked = don't display
*/
connected = false;
}
updateUsbMassStorageNotification(connected);
}
/*
* @override com.android.os.storage.StorageEventListener
*/
@Override
public void onStorageStateChanged(final String path, final String oldState, final String newState) {
mAsyncEventHandler.post(new Runnable() {
@Override
public void run() {
onStorageStateChangedAsync(path, oldState, newState);
}
});
}
private void onStorageStateChangedAsync(String path, String oldState, String newState) {
Slog.i(TAG, String.format(
"Media {%s} state changed from {%s} -> {%s}", path, oldState, newState));
if (newState.equals(Environment.MEDIA_SHARED)) {
/*
* Storage is now shared. Modify the UMS notification
* for stopping UMS.
*/
Intent intent = new Intent();
intent.setClass(mContext, com.android.systemui.usb.UsbStorageActivity.class);
PendingIntent pi = PendingIntent.getActivity(mContext, 0, intent, 0);
setUsbStorageNotification(
com.android.internal.R.string.usb_storage_stop_notification_title,
com.android.internal.R.string.usb_storage_stop_notification_message,
com.android.internal.R.drawable.stat_sys_warning, false, true, pi);
} else if (newState.equals(Environment.MEDIA_CHECKING)) {
/*
* Storage is now checking. Update media notification and disable
* UMS notification.
*/
setMediaStorageNotification(
com.android.internal.R.string.ext_media_checking_notification_title,
com.android.internal.R.string.ext_media_checking_notification_message,
com.android.internal.R.drawable.stat_notify_sdcard_prepare, true, false, null);
updateUsbMassStorageNotification(false);
} else if (newState.equals(Environment.MEDIA_MOUNTED)) {
/*
* Storage is now mounted. Dismiss any media notifications,
* and enable UMS notification if connected.
*/
setMediaStorageNotification(0, 0, 0, false, false, null);
updateUsbMassStorageNotification(mUmsAvailable);
} else if (newState.equals(Environment.MEDIA_UNMOUNTED)) {
/*
* Storage is now unmounted. We may have been unmounted
* because the user is enabling/disabling UMS, in which case we don't
* want to display the 'safe to unmount' notification.
*/
if (!mStorageManager.isUsbMassStorageEnabled()) {
if (oldState.equals(Environment.MEDIA_SHARED)) {
/*
* The unmount was due to UMS being enabled. Dismiss any
* media notifications, and enable UMS notification if connected
*/
setMediaStorageNotification(0, 0, 0, false, false, null);
updateUsbMassStorageNotification(mUmsAvailable);
} else {
/*
* Show safe to unmount media notification, and enable UMS
* notification if connected.
*/
if (Environment.isExternalStorageRemovable()) {
setMediaStorageNotification(
com.android.internal.R.string.ext_media_safe_unmount_notification_title,
com.android.internal.R.string.ext_media_safe_unmount_notification_message,
com.android.internal.R.drawable.stat_notify_sdcard, true, true, null);
} else {
// This device does not have removable storage, so
// don't tell the user they can remove it.
setMediaStorageNotification(0, 0, 0, false, false, null);
}
updateUsbMassStorageNotification(mUmsAvailable);
}
} else {
/*
* The unmount was due to UMS being enabled. Dismiss any
* media notifications, and disable the UMS notification
*/
setMediaStorageNotification(0, 0, 0, false, false, null);
updateUsbMassStorageNotification(false);
}
} else if (newState.equals(Environment.MEDIA_NOFS)) {
/*
* Storage has no filesystem. Show blank media notification,
* and enable UMS notification if connected.
*/
Intent intent = new Intent();
intent.setClass(mContext, com.android.internal.app.ExternalMediaFormatActivity.class);
PendingIntent pi = PendingIntent.getActivity(mContext, 0, intent, 0);
setMediaStorageNotification(
com.android.internal.R.string.ext_media_nofs_notification_title,
com.android.internal.R.string.ext_media_nofs_notification_message,
com.android.internal.R.drawable.stat_notify_sdcard_usb, true, false, pi);
updateUsbMassStorageNotification(mUmsAvailable);
} else if (newState.equals(Environment.MEDIA_UNMOUNTABLE)) {
/*
* Storage is corrupt. Show corrupt media notification,
* and enable UMS notification if connected.
*/
Intent intent = new Intent();
intent.setClass(mContext, com.android.internal.app.ExternalMediaFormatActivity.class);
PendingIntent pi = PendingIntent.getActivity(mContext, 0, intent, 0);
setMediaStorageNotification(
com.android.internal.R.string.ext_media_unmountable_notification_title,
com.android.internal.R.string.ext_media_unmountable_notification_message,
com.android.internal.R.drawable.stat_notify_sdcard_usb, true, false, pi);
updateUsbMassStorageNotification(mUmsAvailable);
} else if (newState.equals(Environment.MEDIA_REMOVED)) {
/*
* Storage has been removed. Show nomedia media notification,
* and disable UMS notification regardless of connection state.
*/
setMediaStorageNotification(
com.android.internal.R.string.ext_media_nomedia_notification_title,
com.android.internal.R.string.ext_media_nomedia_notification_message,
com.android.internal.R.drawable.stat_notify_sdcard_usb,
true, false, null);
updateUsbMassStorageNotification(false);
} else if (newState.equals(Environment.MEDIA_BAD_REMOVAL)) {
/*
* Storage has been removed unsafely. Show bad removal media notification,
* and disable UMS notification regardless of connection state.
*/
setMediaStorageNotification(
com.android.internal.R.string.ext_media_badremoval_notification_title,
com.android.internal.R.string.ext_media_badremoval_notification_message,
com.android.internal.R.drawable.stat_sys_warning,
true, true, null);
updateUsbMassStorageNotification(false);
} else {
Slog.w(TAG, String.format("Ignoring unknown state {%s}", newState));
}
}
/**
* Update the state of the USB mass storage notification
*/
void updateUsbMassStorageNotification(boolean available) {
if (available) {
Intent intent = new Intent();
intent.setClass(mContext, com.android.systemui.usb.UsbStorageActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pi = PendingIntent.getActivity(mContext, 0, intent, 0);
setUsbStorageNotification(
com.android.internal.R.string.usb_storage_notification_title,
com.android.internal.R.string.usb_storage_notification_message,
com.android.internal.R.drawable.stat_sys_data_usb,
false, true, pi);
} else {
setUsbStorageNotification(0, 0, 0, false, false, null);
}
}
/**
* Sets the USB storage notification.
*/
private synchronized void setUsbStorageNotification(int titleId, int messageId, int icon,
boolean sound, boolean visible, PendingIntent pi) {
if (!visible && mUsbStorageNotification == null) {
return;
}
NotificationManager notificationManager = (NotificationManager) mContext
.getSystemService(Context.NOTIFICATION_SERVICE);
if (notificationManager == null) {
return;
}
if (visible) {
Resources r = Resources.getSystem();
CharSequence title = r.getText(titleId);
CharSequence message = r.getText(messageId);
if (mUsbStorageNotification == null) {
mUsbStorageNotification = new Notification();
mUsbStorageNotification.icon = icon;
mUsbStorageNotification.when = 0;
}
if (sound) {
mUsbStorageNotification.defaults |= Notification.DEFAULT_SOUND;
} else {
mUsbStorageNotification.defaults &= ~Notification.DEFAULT_SOUND;
}
mUsbStorageNotification.flags = Notification.FLAG_ONGOING_EVENT;
mUsbStorageNotification.tickerText = title;
if (pi == null) {
Intent intent = new Intent();
pi = PendingIntent.getBroadcast(mContext, 0, intent, 0);
}
mUsbStorageNotification.setLatestEventInfo(mContext, title, message, pi);
final boolean adbOn = 1 == Settings.Secure.getInt(
mContext.getContentResolver(),
Settings.Secure.ADB_ENABLED,
0);
if (POP_UMS_ACTIVITY_ON_CONNECT && !adbOn) {
// Pop up a full-screen alert to coach the user through enabling UMS. The average
// user has attached the device to USB either to charge the phone (in which case
// this is harmless) or transfer files, and in the latter case this alert saves
// several steps (as well as subtly indicates that you shouldn't mix UMS with other
// activities on the device).
//
// If ADB is enabled, however, we suppress this dialog (under the assumption that a
// developer (a) knows how to enable UMS, and (b) is probably using USB to install
// builds or use adb commands.
mUsbStorageNotification.fullScreenIntent = pi;
}
}
final int notificationId = mUsbStorageNotification.icon;
if (visible) {
notificationManager.notify(notificationId, mUsbStorageNotification);
} else {
notificationManager.cancel(notificationId);
}
}
private synchronized boolean getMediaStorageNotificationDismissable() {
if ((mMediaStorageNotification != null) &&
((mMediaStorageNotification.flags & Notification.FLAG_AUTO_CANCEL) ==
Notification.FLAG_AUTO_CANCEL))
return true;
return false;
}
/**
* Sets the media storage notification.
*/
private synchronized void setMediaStorageNotification(int titleId, int messageId, int icon, boolean visible,
boolean dismissable, PendingIntent pi) {
if (!visible && mMediaStorageNotification == null) {
return;
}
NotificationManager notificationManager = (NotificationManager) mContext
.getSystemService(Context.NOTIFICATION_SERVICE);
if (notificationManager == null) {
return;
}
if (mMediaStorageNotification != null && visible) {
/*
* Dismiss the previous notification - we're about to
* re-use it.
*/
final int notificationId = mMediaStorageNotification.icon;
notificationManager.cancel(notificationId);
}
if (visible) {
Resources r = Resources.getSystem();
CharSequence title = r.getText(titleId);
CharSequence message = r.getText(messageId);
if (mMediaStorageNotification == null) {
mMediaStorageNotification = new Notification();
mMediaStorageNotification.when = 0;
}
mMediaStorageNotification.defaults &= ~Notification.DEFAULT_SOUND;
if (dismissable) {
mMediaStorageNotification.flags = Notification.FLAG_AUTO_CANCEL;
} else {
mMediaStorageNotification.flags = Notification.FLAG_ONGOING_EVENT;
}
mMediaStorageNotification.tickerText = title;
if (pi == null) {
Intent intent = new Intent();
pi = PendingIntent.getBroadcast(mContext, 0, intent, 0);
}
mMediaStorageNotification.icon = icon;
mMediaStorageNotification.setLatestEventInfo(mContext, title, message, pi);
}
final int notificationId = mMediaStorageNotification.icon;
if (visible) {
notificationManager.notify(notificationId, mMediaStorageNotification);
} else {
notificationManager.cancel(notificationId);
}
}
}
@@ -0,0 +1,100 @@
/*
* Copyright (C) 2011 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 com.android.systemui.usb;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.hardware.usb.UsbAccessory;
import android.hardware.usb.UsbManager;
import android.os.Bundle;
import android.util.Log;
import com.android.internal.app.AlertActivity;
import com.android.internal.app.AlertController;
import com.android.systemui.R;
/**
* If the attached USB accessory has a URL associated with it, and that URL is valid,
* show this dialog to the user to allow them to optionally visit that URL for more
* information or software downloads.
* Otherwise (no valid URL) this activity does nothing at all, finishing immediately.
*/
public class UsbAccessoryUriActivity extends AlertActivity
implements DialogInterface.OnClickListener {
private static final String TAG = "UsbAccessoryUriActivity";
private UsbAccessory mAccessory;
private Uri mUri;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
Intent intent = getIntent();
mAccessory = (UsbAccessory)intent.getParcelableExtra(UsbManager.EXTRA_ACCESSORY);
String uriString = intent.getStringExtra("uri");
mUri = (uriString == null ? null : Uri.parse(uriString));
// sanity check before displaying dialog
if (mUri == null) {
Log.e(TAG, "could not parse Uri " + uriString);
finish();
return;
}
String scheme = mUri.getScheme();
if (!"http".equals(scheme) && !"https".equals(scheme)) {
Log.e(TAG, "Uri not http or https: " + mUri);
finish();
return;
}
final AlertController.AlertParams ap = mAlertParams;
ap.mTitle = mAccessory.getDescription();
if (ap.mTitle == null || ap.mTitle.length() == 0) {
ap.mTitle = getString(R.string.title_usb_accessory);
}
ap.mMessage = getString(R.string.usb_accessory_uri_prompt, mUri);
ap.mPositiveButtonText = getString(R.string.label_view);
ap.mNegativeButtonText = getString(android.R.string.cancel);
ap.mPositiveButtonListener = this;
ap.mNegativeButtonListener = this;
setupAlert();
}
public void onClick(DialogInterface dialog, int which) {
if (which == AlertDialog.BUTTON_POSITIVE) {
// launch the browser
Intent intent = new Intent(Intent.ACTION_VIEW, mUri);
intent.addCategory(Intent.CATEGORY_BROWSABLE);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
try {
startActivity(intent);
} catch (ActivityNotFoundException e) {
Log.e(TAG, "startActivity failed for " + mUri);
}
}
finish();
}
}
@@ -0,0 +1,143 @@
/*
* Copyright (C) 2011 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 com.android.systemui.usb;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.hardware.usb.IUsbManager;
import android.hardware.usb.UsbAccessory;
import android.hardware.usb.UsbManager;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;
import com.android.internal.app.AlertActivity;
import com.android.internal.app.AlertController;
import com.android.systemui.R;
public class UsbConfirmActivity extends AlertActivity
implements DialogInterface.OnClickListener, CheckBox.OnCheckedChangeListener {
private static final String TAG = "UsbConfirmActivity";
private CheckBox mAlwaysUse;
private TextView mClearDefaultHint;
private UsbAccessory mAccessory;
private ResolveInfo mResolveInfo;
private boolean mPermissionGranted;
private UsbDisconnectedReceiver mDisconnectedReceiver;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
Intent intent = getIntent();
mAccessory = (UsbAccessory)intent.getParcelableExtra(UsbManager.EXTRA_ACCESSORY);
mDisconnectedReceiver = new UsbDisconnectedReceiver(this, mAccessory);
mResolveInfo = (ResolveInfo)intent.getParcelableExtra("rinfo");
PackageManager packageManager = getPackageManager();
String appName = mResolveInfo.loadLabel(packageManager).toString();
final AlertController.AlertParams ap = mAlertParams;
ap.mIcon = mResolveInfo.loadIcon(packageManager);
ap.mTitle = appName;
ap.mMessage = getString(R.string.usb_accessory_confirm_prompt, appName);
ap.mPositiveButtonText = getString(android.R.string.ok);
ap.mNegativeButtonText = getString(android.R.string.cancel);
ap.mPositiveButtonListener = this;
ap.mNegativeButtonListener = this;
// add "always use" checkbox
LayoutInflater inflater = (LayoutInflater)getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
ap.mView = inflater.inflate(com.android.internal.R.layout.always_use_checkbox, null);
mAlwaysUse = (CheckBox)ap.mView.findViewById(com.android.internal.R.id.alwaysUse);
mAlwaysUse.setText(R.string.always_use_accessory);
mAlwaysUse.setOnCheckedChangeListener(this);
mClearDefaultHint = (TextView)ap.mView.findViewById(
com.android.internal.R.id.clearDefaultHint);
mClearDefaultHint.setVisibility(View.GONE);
setupAlert();
}
@Override
protected void onDestroy() {
if (mDisconnectedReceiver != null) {
unregisterReceiver(mDisconnectedReceiver);
}
super.onDestroy();
}
public void onClick(DialogInterface dialog, int which) {
if (which == AlertDialog.BUTTON_POSITIVE) {
try {
IBinder b = ServiceManager.getService(USB_SERVICE);
IUsbManager service = IUsbManager.Stub.asInterface(b);
int uid = mResolveInfo.activityInfo.applicationInfo.uid;
boolean alwaysUse = mAlwaysUse.isChecked();
Intent intent = new Intent(UsbManager.ACTION_USB_ACCESSORY_ATTACHED);
intent.putExtra(UsbManager.EXTRA_ACCESSORY, mAccessory);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setComponent(
new ComponentName(mResolveInfo.activityInfo.packageName,
mResolveInfo.activityInfo.name));
// grant permission for the accessory
service.grantAccessoryPermission(mAccessory, uid);
// set or clear default setting
if (alwaysUse) {
service.setAccessoryPackage(mAccessory,
mResolveInfo.activityInfo.packageName);
} else {
service.setAccessoryPackage(mAccessory, null);
}
startActivity(intent);
} catch (Exception e) {
Log.e(TAG, "Unable to start activity", e);
}
}
finish();
}
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (mClearDefaultHint == null) return;
if(isChecked) {
mClearDefaultHint.setVisibility(View.VISIBLE);
} else {
mClearDefaultHint.setVisibility(View.GONE);
}
}
}
@@ -0,0 +1,52 @@
/*
* Copyright (C) 2010 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 com.android.systemui.usb;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.hardware.usb.UsbAccessory;
import android.hardware.usb.UsbManager;
// This class is used to close UsbPermissionsActivity and UsbResolverActivity
// if their accessory is disconnected while the dialog is still open
class UsbDisconnectedReceiver extends BroadcastReceiver {
private final Activity mActivity;
private UsbAccessory mAccessory;
public UsbDisconnectedReceiver(Activity activity, UsbAccessory accessory) {
mActivity = activity;
mAccessory = accessory;
IntentFilter filter = new IntentFilter(UsbManager.ACTION_USB_ACCESSORY_DETACHED);
activity.registerReceiver(this, filter);
}
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (UsbManager.ACTION_USB_ACCESSORY_DETACHED.equals(action)) {
UsbAccessory accessory =
(UsbAccessory)intent.getParcelableExtra(UsbManager.EXTRA_ACCESSORY);
if (accessory != null && accessory.equals(mAccessory)) {
mActivity.finish();
}
}
}
}
@@ -0,0 +1,153 @@
/*
* Copyright (C) 2011 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 com.android.systemui.usb;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.PendingIntent;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.hardware.usb.IUsbManager;
import android.hardware.usb.UsbAccessory;
import android.hardware.usb.UsbManager;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;
import com.android.internal.app.AlertActivity;
import com.android.internal.app.AlertController;
import com.android.systemui.R;
public class UsbPermissionActivity extends AlertActivity
implements DialogInterface.OnClickListener, CheckBox.OnCheckedChangeListener {
private static final String TAG = "UsbPermissionActivity";
private CheckBox mAlwaysUse;
private TextView mClearDefaultHint;
private UsbAccessory mAccessory;
private PendingIntent mPendingIntent;
private String mPackageName;
private int mUid;
private boolean mPermissionGranted;
private UsbDisconnectedReceiver mDisconnectedReceiver;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
Intent intent = getIntent();
mAccessory = (UsbAccessory)intent.getParcelableExtra(UsbManager.EXTRA_ACCESSORY);
mDisconnectedReceiver = new UsbDisconnectedReceiver(this, mAccessory);
mPendingIntent = (PendingIntent)intent.getParcelableExtra(Intent.EXTRA_INTENT);
mUid = intent.getIntExtra("uid", 0);
mPackageName = intent.getStringExtra("package");
PackageManager packageManager = getPackageManager();
ApplicationInfo aInfo;
try {
aInfo = packageManager.getApplicationInfo(mPackageName, 0);
} catch (PackageManager.NameNotFoundException e) {
Log.e(TAG, "unable to look up package name", e);
finish();
return;
}
String appName = aInfo.loadLabel(packageManager).toString();
final AlertController.AlertParams ap = mAlertParams;
ap.mIcon = aInfo.loadIcon(packageManager);
ap.mTitle = appName;
ap.mMessage = getString(R.string.usb_accessory_permission_prompt, appName);
ap.mPositiveButtonText = getString(android.R.string.ok);
ap.mNegativeButtonText = getString(android.R.string.cancel);
ap.mPositiveButtonListener = this;
ap.mNegativeButtonListener = this;
// add "always use" checkbox
LayoutInflater inflater = (LayoutInflater)getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
ap.mView = inflater.inflate(com.android.internal.R.layout.always_use_checkbox, null);
mAlwaysUse = (CheckBox)ap.mView.findViewById(com.android.internal.R.id.alwaysUse);
mAlwaysUse.setText(R.string.always_use_accessory);
mAlwaysUse.setOnCheckedChangeListener(this);
mClearDefaultHint = (TextView)ap.mView.findViewById(
com.android.internal.R.id.clearDefaultHint);
mClearDefaultHint.setVisibility(View.GONE);
setupAlert();
}
@Override
public void onDestroy() {
IBinder b = ServiceManager.getService(USB_SERVICE);
IUsbManager service = IUsbManager.Stub.asInterface(b);
// send response via pending intent
Intent intent = new Intent();
try {
if (mAccessory != null) {
intent.putExtra(UsbManager.EXTRA_ACCESSORY, mAccessory);
if (mPermissionGranted) {
service.grantAccessoryPermission(mAccessory, mUid);
if (mAlwaysUse.isChecked()) {
service.setAccessoryPackage(mAccessory, mPackageName);
}
}
}
intent.putExtra(UsbManager.EXTRA_PERMISSION_GRANTED, mPermissionGranted);
mPendingIntent.send(this, 0, intent);
} catch (PendingIntent.CanceledException e) {
Log.w(TAG, "PendingIntent was cancelled");
} catch (RemoteException e) {
Log.e(TAG, "IUsbService connection failed", e);
}
if (mDisconnectedReceiver != null) {
unregisterReceiver(mDisconnectedReceiver);
}
super.onDestroy();
}
public void onClick(DialogInterface dialog, int which) {
if (which == AlertDialog.BUTTON_POSITIVE) {
mPermissionGranted = true;
}
finish();
}
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (mClearDefaultHint == null) return;
if(isChecked) {
mClearDefaultHint.setVisibility(View.VISIBLE);
} else {
mClearDefaultHint.setVisibility(View.GONE);
}
}
}
@@ -0,0 +1,108 @@
/*
* Copyright (C) 2011 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 com.android.systemui.usb;
import com.android.internal.app.ResolverActivity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.hardware.usb.IUsbManager;
import android.hardware.usb.UsbAccessory;
import android.hardware.usb.UsbManager;
import android.os.Bundle;
import android.os.IBinder;
import android.os.Parcelable;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.util.Log;
import android.widget.CheckBox;
import com.android.systemui.R;
import java.util.ArrayList;
/* Activity for choosing an application for a USB device or accessory */
public class UsbResolverActivity extends ResolverActivity {
public static final String TAG = "UsbResolverActivity";
public static final String EXTRA_RESOLVE_INFOS = "rlist";
private UsbAccessory mAccessory;
private UsbDisconnectedReceiver mDisconnectedReceiver;
@Override
protected void onCreate(Bundle savedInstanceState) {
Intent intent = getIntent();
Parcelable targetParcelable = intent.getParcelableExtra(Intent.EXTRA_INTENT);
if (!(targetParcelable instanceof Intent)) {
Log.w("UsbResolverActivity", "Target is not an intent: " + targetParcelable);
finish();
return;
}
Intent target = (Intent)targetParcelable;
ArrayList<ResolveInfo> rList = intent.getParcelableArrayListExtra(EXTRA_RESOLVE_INFOS);
CharSequence title = getResources().getText(com.android.internal.R.string.chooseUsbActivity);
super.onCreate(savedInstanceState, target, title, null, rList,
true /* Set alwaysUseOption to true to enable "always use this app" checkbox. */ );
CheckBox alwaysUse = (CheckBox)findViewById(com.android.internal.R.id.alwaysUse);
if (alwaysUse != null) {
alwaysUse.setText(R.string.always_use_accessory);
}
mAccessory = (UsbAccessory)target.getParcelableExtra(UsbManager.EXTRA_ACCESSORY);
if (mAccessory == null) {
Log.e(TAG, "accessory is null");
finish();
return;
}
mDisconnectedReceiver = new UsbDisconnectedReceiver(this, mAccessory);
}
@Override
protected void onDestroy() {
if (mDisconnectedReceiver != null) {
unregisterReceiver(mDisconnectedReceiver);
}
super.onDestroy();
}
protected void onIntentSelected(ResolveInfo ri, Intent intent, boolean alwaysCheck) {
try {
IBinder b = ServiceManager.getService(USB_SERVICE);
IUsbManager service = IUsbManager.Stub.asInterface(b);
int uid = ri.activityInfo.applicationInfo.uid;
// grant permission for the accessory
service.grantAccessoryPermission(mAccessory, uid);
// set or clear default setting
if (alwaysCheck) {
service.setAccessoryPackage(mAccessory, ri.activityInfo.packageName);
} else {
service.setAccessoryPackage(mAccessory, null);
}
try {
startActivity(intent);
} catch (ActivityNotFoundException e) {
Log.e(TAG, "startActivity failed", e);
}
} catch (RemoteException e) {
Log.e(TAG, "onIntentSelected failed", e);
}
}
}
@@ -0,0 +1,346 @@
/*
* Copyright (C) 2007 Google Inc.
*
* 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 com.android.systemui.usb;
import com.android.internal.R;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.DialogInterface.OnCancelListener;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.hardware.usb.UsbManager;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.IBinder;
import android.os.storage.IMountService;
import android.os.storage.StorageManager;
import android.os.storage.StorageEventListener;
import android.os.SystemProperties;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.widget.ImageView;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.util.Log;
import java.util.List;
/**
* This activity is shown to the user for him/her to enable USB mass storage
* on-demand (that is, when the USB cable is connected). It uses the alert
* dialog style. It will be launched from a notification.
*/
public class UsbStorageActivity extends Activity
implements View.OnClickListener, OnCancelListener {
private static final String TAG = "UsbStorageActivity";
private Button mMountButton;
private Button mUnmountButton;
private ProgressBar mProgressBar;
private TextView mBanner;
private TextView mMessage;
private ImageView mIcon;
private StorageManager mStorageManager = null;
private static final int DLG_CONFIRM_KILL_STORAGE_USERS = 1;
private static final int DLG_ERROR_SHARING = 2;
static final boolean localLOGV = false;
private boolean mDestroyed;
// UI thread
private Handler mUIHandler;
// thread for working with the storage services, which can be slow
private Handler mAsyncStorageHandler;
/** Used to detect when the USB cable is unplugged, so we can call finish() */
private BroadcastReceiver mUsbStateReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(UsbManager.ACTION_USB_STATE)) {
handleUsbStateChanged(intent);
}
}
};
private StorageEventListener mStorageListener = new StorageEventListener() {
@Override
public void onStorageStateChanged(String path, String oldState, String newState) {
final boolean on = newState.equals(Environment.MEDIA_SHARED);
switchDisplay(on);
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (mStorageManager == null) {
mStorageManager = (StorageManager) getSystemService(Context.STORAGE_SERVICE);
if (mStorageManager == null) {
Log.w(TAG, "Failed to get StorageManager");
}
}
mUIHandler = new Handler();
HandlerThread thr = new HandlerThread("SystemUI UsbStorageActivity");
thr.start();
mAsyncStorageHandler = new Handler(thr.getLooper());
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setProgressBarIndeterminateVisibility(true);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
if (Environment.isExternalStorageRemovable()) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
}
setTitle(getString(com.android.internal.R.string.usb_storage_activity_title));
setContentView(com.android.internal.R.layout.usb_storage_activity);
mIcon = (ImageView) findViewById(com.android.internal.R.id.icon);
mBanner = (TextView) findViewById(com.android.internal.R.id.banner);
mMessage = (TextView) findViewById(com.android.internal.R.id.message);
mMountButton = (Button) findViewById(com.android.internal.R.id.mount_button);
mMountButton.setOnClickListener(this);
mUnmountButton = (Button) findViewById(com.android.internal.R.id.unmount_button);
mUnmountButton.setOnClickListener(this);
mProgressBar = (ProgressBar) findViewById(com.android.internal.R.id.progress);
}
@Override
protected void onDestroy() {
super.onDestroy();
mDestroyed = true;
}
private void switchDisplay(final boolean usbStorageInUse) {
mUIHandler.post(new Runnable() {
@Override
public void run() {
switchDisplayAsync(usbStorageInUse);
}
});
}
private void switchDisplayAsync(boolean usbStorageInUse) {
if (usbStorageInUse) {
mProgressBar.setVisibility(View.GONE);
mUnmountButton.setVisibility(View.VISIBLE);
mMountButton.setVisibility(View.GONE);
mIcon.setImageResource(com.android.internal.R.drawable.usb_android_connected);
mBanner.setText(com.android.internal.R.string.usb_storage_stop_title);
mMessage.setText(com.android.internal.R.string.usb_storage_stop_message);
} else {
mProgressBar.setVisibility(View.GONE);
mUnmountButton.setVisibility(View.GONE);
mMountButton.setVisibility(View.VISIBLE);
mIcon.setImageResource(com.android.internal.R.drawable.usb_android);
mBanner.setText(com.android.internal.R.string.usb_storage_title);
mMessage.setText(com.android.internal.R.string.usb_storage_message);
}
}
@Override
protected void onResume() {
super.onResume();
mStorageManager.registerListener(mStorageListener);
registerReceiver(mUsbStateReceiver, new IntentFilter(UsbManager.ACTION_USB_STATE));
try {
mAsyncStorageHandler.post(new Runnable() {
@Override
public void run() {
switchDisplay(mStorageManager.isUsbMassStorageEnabled());
}
});
} catch (Exception ex) {
Log.e(TAG, "Failed to read UMS enable state", ex);
}
}
@Override
protected void onPause() {
super.onPause();
unregisterReceiver(mUsbStateReceiver);
if (mStorageManager == null && mStorageListener != null) {
mStorageManager.unregisterListener(mStorageListener);
}
}
private void handleUsbStateChanged(Intent intent) {
boolean connected = intent.getExtras().getBoolean(UsbManager.USB_CONNECTED);
if (!connected) {
// It was disconnected from the plug, so finish
finish();
}
}
private IMountService getMountService() {
IBinder service = ServiceManager.getService("mount");
if (service != null) {
return IMountService.Stub.asInterface(service);
}
return null;
}
@Override
public Dialog onCreateDialog(int id, Bundle args) {
switch (id) {
case DLG_CONFIRM_KILL_STORAGE_USERS:
return new AlertDialog.Builder(this)
.setTitle(R.string.dlg_confirm_kill_storage_users_title)
.setPositiveButton(R.string.dlg_ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
switchUsbMassStorage(true);
}})
.setNegativeButton(R.string.cancel, null)
.setMessage(R.string.dlg_confirm_kill_storage_users_text)
.setOnCancelListener(this)
.create();
case DLG_ERROR_SHARING:
return new AlertDialog.Builder(this)
.setTitle(R.string.dlg_error_title)
.setNeutralButton(R.string.dlg_ok, null)
.setMessage(R.string.usb_storage_error_message)
.setOnCancelListener(this)
.create();
}
return null;
}
private void scheduleShowDialog(final int id) {
mUIHandler.post(new Runnable() {
@Override
public void run() {
if (!mDestroyed) {
removeDialog(id);
showDialog(id);
}
}
});
}
private void switchUsbMassStorage(final boolean on) {
if(SystemProperties.getBoolean("ro.monkey", false)) {
Log.d(TAG,"Monkey Running: Switching to UsbMassStorage disabled");
return;
}
// things to do on the UI thread
mUIHandler.post(new Runnable() {
@Override
public void run() {
mUnmountButton.setVisibility(View.GONE);
mMountButton.setVisibility(View.GONE);
mProgressBar.setVisibility(View.VISIBLE);
// will be hidden once USB mass storage kicks in (or fails)
}
});
// things to do elsewhere
mAsyncStorageHandler.post(new Runnable() {
@Override
public void run() {
if (on) {
mStorageManager.enableUsbMassStorage();
} else {
mStorageManager.disableUsbMassStorage();
}
}
});
}
private void checkStorageUsers() {
mAsyncStorageHandler.post(new Runnable() {
@Override
public void run() {
checkStorageUsersAsync();
}
});
}
private void checkStorageUsersAsync() {
IMountService ims = getMountService();
if (ims == null) {
// Display error dialog
scheduleShowDialog(DLG_ERROR_SHARING);
}
String extStoragePath = Environment.getExternalStorageDirectory().toString();
boolean showDialog = false;
try {
int[] stUsers = ims.getStorageUsers(extStoragePath);
if (stUsers != null && stUsers.length > 0) {
showDialog = true;
} else {
// List of applications on sdcard.
ActivityManager am = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
List<ApplicationInfo> infoList = am.getRunningExternalApplications();
if (infoList != null && infoList.size() > 0) {
showDialog = true;
}
}
} catch (RemoteException e) {
// Display error dialog
scheduleShowDialog(DLG_ERROR_SHARING);
}
if (showDialog) {
// Display dialog to user
scheduleShowDialog(DLG_CONFIRM_KILL_STORAGE_USERS);
} else {
if (localLOGV) Log.i(TAG, "Enabling UMS");
switchUsbMassStorage(true);
}
}
public void onClick(View v) {
if (v == mMountButton) {
// notify MountService about changing volume state to shared
mStorageManager.setShared(true);
// Check for list of storage users and display dialog if needed.
checkStorageUsers();
} else if (v == mUnmountButton) {
mStorageManager.setShared(false);
if (localLOGV) Log.i(TAG, "Disabling UMS");
switchUsbMassStorage(false);
}
}
public void onCancel(DialogInterface dialog) {
finish();
}
}