Loading packages/SystemUI/src/com/android/systemui/people/PeopleSpaceActivity.java +16 −18 Original line number Diff line number Diff line Loading @@ -25,20 +25,20 @@ import android.content.pm.PackageManager; import android.content.pm.ShortcutInfo; import android.os.Bundle; import android.os.ServiceManager; import android.os.UserHandle; import android.util.Log; import android.view.ViewGroup; import com.android.systemui.R; import java.util.List; import java.util.Map; /** * Shows the user their tiles for their priority People (go/live-status). */ public class PeopleSpaceActivity extends Activity { private static String sTAG = "PeopleSpaceActivity"; private static final String TAG = "PeopleSpaceActivity"; private ViewGroup mPeopleSpaceLayout; private IPeopleManager mPeopleManager; Loading @@ -53,8 +53,7 @@ public class PeopleSpaceActivity extends Activity { setContentView(R.layout.people_space_activity); mPeopleSpaceLayout = findViewById(R.id.people_space_layout); mContext = getApplicationContext(); mNotificationManager = INotificationManager.Stub.asInterface( mNotificationManager = INotificationManager.Stub.asInterface( ServiceManager.getService(Context.NOTIFICATION_SERVICE)); mPackageManager = getPackageManager(); mPeopleManager = IPeopleManager.Stub.asInterface( Loading @@ -69,27 +68,26 @@ public class PeopleSpaceActivity extends Activity { */ private void setTileViewsWithPriorityConversations() { try { List<ShortcutInfo> shortcutInfos = PeopleSpaceUtils.getShortcutInfos(mContext, mNotificationManager, mPeopleManager); for (ShortcutInfo conversation : shortcutInfos) { List<Map.Entry<Long, ShortcutInfo>> shortcutInfos = PeopleSpaceUtils.getShortcutInfos( mContext, mNotificationManager, mPeopleManager); for (Map.Entry<Long, ShortcutInfo> entry : shortcutInfos) { ShortcutInfo shortcutInfo = entry.getValue(); PeopleSpaceTileView tileView = new PeopleSpaceTileView(mContext, mPeopleSpaceLayout, conversation.getId()); setTileView(tileView, conversation); shortcutInfo.getId()); setTileView(tileView, shortcutInfo, entry.getKey()); } } catch (Exception e) { Log.e(sTAG, "Couldn't retrieve conversations", e); Log.e(TAG, "Couldn't retrieve conversations", e); } } /** Sets {@code tileView} with the data in {@code conversation}. */ private void setTileView(PeopleSpaceTileView tileView, ShortcutInfo shortcutInfo) { private void setTileView(PeopleSpaceTileView tileView, ShortcutInfo shortcutInfo, long lastInteraction) { try { int userId = UserHandle.getUserHandleForUid(shortcutInfo.getUserId()).getIdentifier(); String pkg = shortcutInfo.getPackage(); long lastInteraction = mPeopleManager.getLastInteraction(pkg, userId, shortcutInfo.getId()); String status = PeopleSpaceUtils.getLastInteractionString(mContext, lastInteraction); String status = PeopleSpaceUtils.getLastInteractionString(mContext, lastInteraction); tileView.setStatus(status); tileView.setName(shortcutInfo.getLabel().toString()); Loading @@ -97,7 +95,7 @@ public class PeopleSpaceActivity extends Activity { tileView.setPersonIcon(mLauncherApps.getShortcutIconDrawable(shortcutInfo, 0)); tileView.setOnClickListener(mLauncherApps, shortcutInfo); } catch (Exception e) { Log.e(sTAG, "Couldn't retrieve shortcut information", e); Log.e(TAG, "Couldn't retrieve shortcut information", e); } } Loading packages/SystemUI/src/com/android/systemui/people/PeopleSpaceUtils.java +38 −11 Original line number Diff line number Diff line Loading @@ -28,15 +28,19 @@ import android.graphics.drawable.Drawable; import android.icu.text.MeasureFormat; import android.icu.util.Measure; import android.icu.util.MeasureUnit; import android.os.UserHandle; import android.provider.Settings; import android.service.notification.ConversationChannelWrapper; import android.util.Log; import com.android.systemui.R; import java.time.Duration; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.stream.Collectors; import java.util.stream.Stream; /** Utils class for People Space. */ public class PeopleSpaceUtils { Loading @@ -47,27 +51,50 @@ public class PeopleSpaceUtils { private static final int MIN_HOUR = 1; private static final int ONE_DAY = 1; /** Returns a list of {@link ShortcutInfo} corresponding to user's conversations. */ public static List<ShortcutInfo> getShortcutInfos(Context context, /** Returns a list of map entries corresponding to user's conversations. */ public static List<Map.Entry<Long, ShortcutInfo>> getShortcutInfos(Context context, INotificationManager notificationManager, IPeopleManager peopleManager) throws Exception { boolean showAllConversations = Settings.Global.getInt(context.getContentResolver(), Settings.Global.PEOPLE_SPACE_CONVERSATION_TYPE, 0) == 0; List<ConversationChannelWrapper> conversations = notificationManager.getConversations( !showAllConversations /* priority only */).getList(); List<ShortcutInfo> shortcutInfos = conversations.stream().filter( c -> shouldKeepConversation(c)).map(c -> c.getShortcutInfo()).collect( Collectors.toList()); true).getList(); List<Map.Entry<Long, ShortcutInfo>> shortcutInfos = getSortedShortcutInfos(peopleManager, conversations.stream().map(c -> c.getShortcutInfo())); if (showAllConversations) { List<ConversationChannel> recentConversations = peopleManager.getRecentConversations().getList(); List<ShortcutInfo> recentShortcuts = recentConversations.stream().map( c -> c.getShortcutInfo()).collect(Collectors.toList()); shortcutInfos.addAll(recentShortcuts); List<Map.Entry<Long, ShortcutInfo>> recentShortcutInfos = getSortedShortcutInfos( peopleManager, recentConversations.stream().map(c -> c.getShortcutInfo())); shortcutInfos.addAll(recentShortcutInfos); } return shortcutInfos; } /** Returns a list sorted by ascending last interaction time from {@code stream}. */ private static List<Map.Entry<Long, ShortcutInfo>> getSortedShortcutInfos( IPeopleManager peopleManager, Stream<ShortcutInfo> stream) { return stream .filter(c -> shouldKeepConversation(c)) .map(c -> Map.entry(getLastInteraction(peopleManager, c), c)) .sorted((c1, c2) -> (c2.getKey().compareTo(c1.getKey()))) .collect(Collectors.toList()); } /** Returns the last interaction time with the user specified by {@code shortcutInfo}. */ private static Long getLastInteraction(IPeopleManager peopleManager, ShortcutInfo shortcutInfo) { try { int userId = UserHandle.getUserHandleForUid(shortcutInfo.getUserId()).getIdentifier(); String pkg = shortcutInfo.getPackage(); return peopleManager.getLastInteraction(pkg, userId, shortcutInfo.getId()); } catch (Exception e) { Log.e(TAG, "Couldn't retrieve last interaction time", e); return 0L; } } /** Converts {@code drawable} to a {@link Bitmap}. */ public static Bitmap convertDrawableToBitmap(Drawable drawable) { if (drawable == null) { Loading Loading @@ -99,6 +126,7 @@ public class PeopleSpaceUtils { /** Returns a readable status describing the {@code lastInteraction}. */ public static String getLastInteractionString(Context context, long lastInteraction) { if (lastInteraction == 0L) { Log.e(TAG, "Could not get valid last interaction"); return context.getString(R.string.basic_status); } long now = System.currentTimeMillis(); Loading Loading @@ -134,8 +162,7 @@ public class PeopleSpaceUtils { * </ul> * </li> */ public static boolean shouldKeepConversation(ConversationChannelWrapper conversation) { ShortcutInfo shortcutInfo = conversation.getShortcutInfo(); public static boolean shouldKeepConversation(ShortcutInfo shortcutInfo) { return shortcutInfo != null && shortcutInfo.getLabel().length() != 0; } Loading packages/SystemUI/src/com/android/systemui/people/widget/PeopleSpaceWidgetRemoteViewsFactory.java +7 −9 Original line number Diff line number Diff line Loading @@ -24,7 +24,6 @@ import android.content.pm.LauncherApps; import android.content.pm.PackageManager; import android.content.pm.ShortcutInfo; import android.os.ServiceManager; import android.os.UserHandle; import android.util.Log; import android.widget.RemoteViews; import android.widget.RemoteViewsService; Loading @@ -35,6 +34,7 @@ import com.android.systemui.people.PeopleSpaceUtils; import java.util.ArrayList; import java.util.List; import java.util.Map; /** People Space Widget RemoteViewsFactory class. */ public class PeopleSpaceWidgetRemoteViewsFactory implements RemoteViewsService.RemoteViewsFactory { Loading @@ -45,8 +45,8 @@ public class PeopleSpaceWidgetRemoteViewsFactory implements RemoteViewsService.R private INotificationManager mNotificationManager; private PackageManager mPackageManager; private LauncherApps mLauncherApps; private List<ShortcutInfo> mShortcutInfos = new ArrayList<>(); private final Context mContext; private List<Map.Entry<Long, ShortcutInfo>> mShortcutInfos = new ArrayList<>(); private Context mContext; public PeopleSpaceWidgetRemoteViewsFactory(Context context, Intent intent) { this.mContext = context; Loading Loading @@ -100,11 +100,9 @@ public class PeopleSpaceWidgetRemoteViewsFactory implements RemoteViewsService.R RemoteViews personView = new RemoteViews(mContext.getPackageName(), R.layout.people_space_widget_item); try { ShortcutInfo shortcutInfo = mShortcutInfos.get(i); int userId = UserHandle.getUserHandleForUid(shortcutInfo.getUserId()).getIdentifier(); String pkg = shortcutInfo.getPackage(); long lastInteraction = mPeopleManager.getLastInteraction(pkg, userId, shortcutInfo.getId()); Map.Entry<Long, ShortcutInfo> entry = mShortcutInfos.get(i); ShortcutInfo shortcutInfo = entry.getValue(); long lastInteraction = entry.getKey(); String status = PeopleSpaceUtils.getLastInteractionString(mContext, lastInteraction); Loading @@ -114,7 +112,7 @@ public class PeopleSpaceWidgetRemoteViewsFactory implements RemoteViewsService.R personView.setImageViewBitmap( R.id.package_icon, PeopleSpaceUtils.convertDrawableToBitmap( mPackageManager.getApplicationIcon(pkg) mPackageManager.getApplicationIcon(shortcutInfo.getPackage()) ) ); personView.setImageViewBitmap( Loading Loading
packages/SystemUI/src/com/android/systemui/people/PeopleSpaceActivity.java +16 −18 Original line number Diff line number Diff line Loading @@ -25,20 +25,20 @@ import android.content.pm.PackageManager; import android.content.pm.ShortcutInfo; import android.os.Bundle; import android.os.ServiceManager; import android.os.UserHandle; import android.util.Log; import android.view.ViewGroup; import com.android.systemui.R; import java.util.List; import java.util.Map; /** * Shows the user their tiles for their priority People (go/live-status). */ public class PeopleSpaceActivity extends Activity { private static String sTAG = "PeopleSpaceActivity"; private static final String TAG = "PeopleSpaceActivity"; private ViewGroup mPeopleSpaceLayout; private IPeopleManager mPeopleManager; Loading @@ -53,8 +53,7 @@ public class PeopleSpaceActivity extends Activity { setContentView(R.layout.people_space_activity); mPeopleSpaceLayout = findViewById(R.id.people_space_layout); mContext = getApplicationContext(); mNotificationManager = INotificationManager.Stub.asInterface( mNotificationManager = INotificationManager.Stub.asInterface( ServiceManager.getService(Context.NOTIFICATION_SERVICE)); mPackageManager = getPackageManager(); mPeopleManager = IPeopleManager.Stub.asInterface( Loading @@ -69,27 +68,26 @@ public class PeopleSpaceActivity extends Activity { */ private void setTileViewsWithPriorityConversations() { try { List<ShortcutInfo> shortcutInfos = PeopleSpaceUtils.getShortcutInfos(mContext, mNotificationManager, mPeopleManager); for (ShortcutInfo conversation : shortcutInfos) { List<Map.Entry<Long, ShortcutInfo>> shortcutInfos = PeopleSpaceUtils.getShortcutInfos( mContext, mNotificationManager, mPeopleManager); for (Map.Entry<Long, ShortcutInfo> entry : shortcutInfos) { ShortcutInfo shortcutInfo = entry.getValue(); PeopleSpaceTileView tileView = new PeopleSpaceTileView(mContext, mPeopleSpaceLayout, conversation.getId()); setTileView(tileView, conversation); shortcutInfo.getId()); setTileView(tileView, shortcutInfo, entry.getKey()); } } catch (Exception e) { Log.e(sTAG, "Couldn't retrieve conversations", e); Log.e(TAG, "Couldn't retrieve conversations", e); } } /** Sets {@code tileView} with the data in {@code conversation}. */ private void setTileView(PeopleSpaceTileView tileView, ShortcutInfo shortcutInfo) { private void setTileView(PeopleSpaceTileView tileView, ShortcutInfo shortcutInfo, long lastInteraction) { try { int userId = UserHandle.getUserHandleForUid(shortcutInfo.getUserId()).getIdentifier(); String pkg = shortcutInfo.getPackage(); long lastInteraction = mPeopleManager.getLastInteraction(pkg, userId, shortcutInfo.getId()); String status = PeopleSpaceUtils.getLastInteractionString(mContext, lastInteraction); String status = PeopleSpaceUtils.getLastInteractionString(mContext, lastInteraction); tileView.setStatus(status); tileView.setName(shortcutInfo.getLabel().toString()); Loading @@ -97,7 +95,7 @@ public class PeopleSpaceActivity extends Activity { tileView.setPersonIcon(mLauncherApps.getShortcutIconDrawable(shortcutInfo, 0)); tileView.setOnClickListener(mLauncherApps, shortcutInfo); } catch (Exception e) { Log.e(sTAG, "Couldn't retrieve shortcut information", e); Log.e(TAG, "Couldn't retrieve shortcut information", e); } } Loading
packages/SystemUI/src/com/android/systemui/people/PeopleSpaceUtils.java +38 −11 Original line number Diff line number Diff line Loading @@ -28,15 +28,19 @@ import android.graphics.drawable.Drawable; import android.icu.text.MeasureFormat; import android.icu.util.Measure; import android.icu.util.MeasureUnit; import android.os.UserHandle; import android.provider.Settings; import android.service.notification.ConversationChannelWrapper; import android.util.Log; import com.android.systemui.R; import java.time.Duration; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.stream.Collectors; import java.util.stream.Stream; /** Utils class for People Space. */ public class PeopleSpaceUtils { Loading @@ -47,27 +51,50 @@ public class PeopleSpaceUtils { private static final int MIN_HOUR = 1; private static final int ONE_DAY = 1; /** Returns a list of {@link ShortcutInfo} corresponding to user's conversations. */ public static List<ShortcutInfo> getShortcutInfos(Context context, /** Returns a list of map entries corresponding to user's conversations. */ public static List<Map.Entry<Long, ShortcutInfo>> getShortcutInfos(Context context, INotificationManager notificationManager, IPeopleManager peopleManager) throws Exception { boolean showAllConversations = Settings.Global.getInt(context.getContentResolver(), Settings.Global.PEOPLE_SPACE_CONVERSATION_TYPE, 0) == 0; List<ConversationChannelWrapper> conversations = notificationManager.getConversations( !showAllConversations /* priority only */).getList(); List<ShortcutInfo> shortcutInfos = conversations.stream().filter( c -> shouldKeepConversation(c)).map(c -> c.getShortcutInfo()).collect( Collectors.toList()); true).getList(); List<Map.Entry<Long, ShortcutInfo>> shortcutInfos = getSortedShortcutInfos(peopleManager, conversations.stream().map(c -> c.getShortcutInfo())); if (showAllConversations) { List<ConversationChannel> recentConversations = peopleManager.getRecentConversations().getList(); List<ShortcutInfo> recentShortcuts = recentConversations.stream().map( c -> c.getShortcutInfo()).collect(Collectors.toList()); shortcutInfos.addAll(recentShortcuts); List<Map.Entry<Long, ShortcutInfo>> recentShortcutInfos = getSortedShortcutInfos( peopleManager, recentConversations.stream().map(c -> c.getShortcutInfo())); shortcutInfos.addAll(recentShortcutInfos); } return shortcutInfos; } /** Returns a list sorted by ascending last interaction time from {@code stream}. */ private static List<Map.Entry<Long, ShortcutInfo>> getSortedShortcutInfos( IPeopleManager peopleManager, Stream<ShortcutInfo> stream) { return stream .filter(c -> shouldKeepConversation(c)) .map(c -> Map.entry(getLastInteraction(peopleManager, c), c)) .sorted((c1, c2) -> (c2.getKey().compareTo(c1.getKey()))) .collect(Collectors.toList()); } /** Returns the last interaction time with the user specified by {@code shortcutInfo}. */ private static Long getLastInteraction(IPeopleManager peopleManager, ShortcutInfo shortcutInfo) { try { int userId = UserHandle.getUserHandleForUid(shortcutInfo.getUserId()).getIdentifier(); String pkg = shortcutInfo.getPackage(); return peopleManager.getLastInteraction(pkg, userId, shortcutInfo.getId()); } catch (Exception e) { Log.e(TAG, "Couldn't retrieve last interaction time", e); return 0L; } } /** Converts {@code drawable} to a {@link Bitmap}. */ public static Bitmap convertDrawableToBitmap(Drawable drawable) { if (drawable == null) { Loading Loading @@ -99,6 +126,7 @@ public class PeopleSpaceUtils { /** Returns a readable status describing the {@code lastInteraction}. */ public static String getLastInteractionString(Context context, long lastInteraction) { if (lastInteraction == 0L) { Log.e(TAG, "Could not get valid last interaction"); return context.getString(R.string.basic_status); } long now = System.currentTimeMillis(); Loading Loading @@ -134,8 +162,7 @@ public class PeopleSpaceUtils { * </ul> * </li> */ public static boolean shouldKeepConversation(ConversationChannelWrapper conversation) { ShortcutInfo shortcutInfo = conversation.getShortcutInfo(); public static boolean shouldKeepConversation(ShortcutInfo shortcutInfo) { return shortcutInfo != null && shortcutInfo.getLabel().length() != 0; } Loading
packages/SystemUI/src/com/android/systemui/people/widget/PeopleSpaceWidgetRemoteViewsFactory.java +7 −9 Original line number Diff line number Diff line Loading @@ -24,7 +24,6 @@ import android.content.pm.LauncherApps; import android.content.pm.PackageManager; import android.content.pm.ShortcutInfo; import android.os.ServiceManager; import android.os.UserHandle; import android.util.Log; import android.widget.RemoteViews; import android.widget.RemoteViewsService; Loading @@ -35,6 +34,7 @@ import com.android.systemui.people.PeopleSpaceUtils; import java.util.ArrayList; import java.util.List; import java.util.Map; /** People Space Widget RemoteViewsFactory class. */ public class PeopleSpaceWidgetRemoteViewsFactory implements RemoteViewsService.RemoteViewsFactory { Loading @@ -45,8 +45,8 @@ public class PeopleSpaceWidgetRemoteViewsFactory implements RemoteViewsService.R private INotificationManager mNotificationManager; private PackageManager mPackageManager; private LauncherApps mLauncherApps; private List<ShortcutInfo> mShortcutInfos = new ArrayList<>(); private final Context mContext; private List<Map.Entry<Long, ShortcutInfo>> mShortcutInfos = new ArrayList<>(); private Context mContext; public PeopleSpaceWidgetRemoteViewsFactory(Context context, Intent intent) { this.mContext = context; Loading Loading @@ -100,11 +100,9 @@ public class PeopleSpaceWidgetRemoteViewsFactory implements RemoteViewsService.R RemoteViews personView = new RemoteViews(mContext.getPackageName(), R.layout.people_space_widget_item); try { ShortcutInfo shortcutInfo = mShortcutInfos.get(i); int userId = UserHandle.getUserHandleForUid(shortcutInfo.getUserId()).getIdentifier(); String pkg = shortcutInfo.getPackage(); long lastInteraction = mPeopleManager.getLastInteraction(pkg, userId, shortcutInfo.getId()); Map.Entry<Long, ShortcutInfo> entry = mShortcutInfos.get(i); ShortcutInfo shortcutInfo = entry.getValue(); long lastInteraction = entry.getKey(); String status = PeopleSpaceUtils.getLastInteractionString(mContext, lastInteraction); Loading @@ -114,7 +112,7 @@ public class PeopleSpaceWidgetRemoteViewsFactory implements RemoteViewsService.R personView.setImageViewBitmap( R.id.package_icon, PeopleSpaceUtils.convertDrawableToBitmap( mPackageManager.getApplicationIcon(pkg) mPackageManager.getApplicationIcon(shortcutInfo.getPackage()) ) ); personView.setImageViewBitmap( Loading