Loading src/com/android/settings/applications/AppStateNotificationBridge.java +13 −19 Original line number Diff line number Diff line Loading @@ -24,8 +24,10 @@ import android.os.UserManager; import android.text.format.DateUtils; import android.util.ArrayMap; import android.util.Log; import android.util.Slog; import android.view.View; import android.view.ViewGroup; import android.widget.CompoundButton; import android.widget.Switch; import com.android.settings.R; Loading Loading @@ -222,27 +224,19 @@ public class AppStateNotificationBridge extends AppStateBaseBridge { return userId + "|" + pkg; } public View.OnClickListener getSwitchOnClickListener(final AppEntry entry) { if (entry != null) { return v -> { ViewGroup view = (ViewGroup) v; Switch toggle = view.findViewById(R.id.switchWidget); if (toggle != null) { if (!toggle.isEnabled()) { return; public CompoundButton.OnCheckedChangeListener getSwitchOnCheckedListener(final AppEntry entry) { if (entry == null) { return null; } toggle.toggle(); return (buttonView, isChecked) -> { mBackend.setNotificationsEnabledForPackage( entry.info.packageName, entry.info.uid, toggle.isChecked()); entry.info.packageName, entry.info.uid, isChecked); NotificationsSentState stats = getNotificationsSentState(entry); if (stats != null) { stats.blocked = !toggle.isChecked(); } stats.blocked = !isChecked; } }; } return null; } public static final AppFilter FILTER_APP_NOTIFICATION_RECENCY = new AppFilter() { @Override Loading src/com/android/settings/applications/manageapplications/ApplicationViewHolder.java +2 −2 Original line number Diff line number Diff line Loading @@ -155,13 +155,13 @@ public class ApplicationViewHolder extends RecyclerView.ViewHolder { } } void updateSwitch(View.OnClickListener listener, boolean enabled, boolean checked) { void updateSwitch(Switch.OnCheckedChangeListener listener, boolean enabled, boolean checked) { if (mSwitch != null && mWidgetContainer != null) { mWidgetContainer.setOnClickListener(listener); mWidgetContainer.setFocusable(false); mWidgetContainer.setClickable(false); mSwitch.setFocusable(true); mSwitch.setClickable(true); mSwitch.setOnCheckedChangeListener(listener); mSwitch.setChecked(checked); mSwitch.setEnabled(enabled); } Loading src/com/android/settings/applications/manageapplications/ManageApplications.java +1 −1 Original line number Diff line number Diff line Loading @@ -1505,7 +1505,7 @@ public class ManageApplications extends InstrumentedFragment switch (mManageApplications.mListType) { case LIST_TYPE_NOTIFICATION: holder.updateSwitch(((AppStateNotificationBridge) mExtraInfoBridge) .getSwitchOnClickListener(entry), .getSwitchOnCheckedListener(entry), AppStateNotificationBridge.enableSwitch(entry), AppStateNotificationBridge.checkSwitch(entry)); if (entry.extraInfo != null Loading tests/robotests/src/com/android/settings/applications/AppStateNotificationBridgeTest.java +4 −6 Original line number Diff line number Diff line Loading @@ -53,6 +53,7 @@ import android.os.RemoteException; import android.os.UserHandle; import android.os.UserManager; import android.view.ViewGroup; import android.widget.CompoundButton; import android.widget.Switch; import com.android.settings.R; Loading Loading @@ -550,12 +551,10 @@ public class AppStateNotificationBridgeTest { } @Test public void testSwitchOnClickListener() { ViewGroup parent = mock(ViewGroup.class); public void testSwitchOnChangeListener() { Switch toggle = mock(Switch.class); when(toggle.isChecked()).thenReturn(true); when(toggle.isEnabled()).thenReturn(true); when(parent.findViewById(anyInt())).thenReturn(toggle); AppEntry entry = mock(AppEntry.class); entry.info = new ApplicationInfo(); Loading @@ -563,10 +562,9 @@ public class AppStateNotificationBridgeTest { entry.info.uid = 1356; entry.extraInfo = new NotificationsSentState(); ViewGroup.OnClickListener listener = mBridge.getSwitchOnClickListener(entry); listener.onClick(parent); CompoundButton.OnCheckedChangeListener listener = mBridge.getSwitchOnCheckedListener(entry); listener.onCheckedChanged(toggle, true); verify(toggle).toggle(); verify(mBackend).setNotificationsEnabledForPackage( entry.info.packageName, entry.info.uid, true); assertThat(((NotificationsSentState) entry.extraInfo).blocked).isFalse(); Loading tests/robotests/src/com/android/settings/applications/manageapplications/ApplicationViewHolderTest.java +8 −3 Original line number Diff line number Diff line Loading @@ -35,6 +35,8 @@ import org.junit.runner.RunWith; import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; import java.util.concurrent.CountDownLatch; @RunWith(RobolectricTestRunner.class) public class ApplicationViewHolderTest { Loading Loading @@ -123,13 +125,16 @@ public class ApplicationViewHolderTest { @Test public void updateSwitch() { final CountDownLatch latch = new CountDownLatch(1); mView = ApplicationViewHolder.newView(new FrameLayout(mContext), true); mHolder = new ApplicationViewHolder(mView); mHolder.updateSwitch(v -> { } /* listener */, true, true); mHolder.updateSwitch((buttonView, isChecked) -> latch.countDown(), true, true); assertThat(mHolder.mSwitch.isChecked()).isTrue(); assertThat(mHolder.mSwitch.isEnabled()).isTrue(); assertThat(mHolder.mWidgetContainer.hasOnClickListeners()).isTrue(); assertThat(mHolder.mSwitch.isFocusable()).isTrue(); assertThat(mHolder.mSwitch.isClickable()).isTrue(); mHolder.mSwitch.callOnClick(); assertThat(latch.getCount()).isEqualTo(0); } } Loading
src/com/android/settings/applications/AppStateNotificationBridge.java +13 −19 Original line number Diff line number Diff line Loading @@ -24,8 +24,10 @@ import android.os.UserManager; import android.text.format.DateUtils; import android.util.ArrayMap; import android.util.Log; import android.util.Slog; import android.view.View; import android.view.ViewGroup; import android.widget.CompoundButton; import android.widget.Switch; import com.android.settings.R; Loading Loading @@ -222,27 +224,19 @@ public class AppStateNotificationBridge extends AppStateBaseBridge { return userId + "|" + pkg; } public View.OnClickListener getSwitchOnClickListener(final AppEntry entry) { if (entry != null) { return v -> { ViewGroup view = (ViewGroup) v; Switch toggle = view.findViewById(R.id.switchWidget); if (toggle != null) { if (!toggle.isEnabled()) { return; public CompoundButton.OnCheckedChangeListener getSwitchOnCheckedListener(final AppEntry entry) { if (entry == null) { return null; } toggle.toggle(); return (buttonView, isChecked) -> { mBackend.setNotificationsEnabledForPackage( entry.info.packageName, entry.info.uid, toggle.isChecked()); entry.info.packageName, entry.info.uid, isChecked); NotificationsSentState stats = getNotificationsSentState(entry); if (stats != null) { stats.blocked = !toggle.isChecked(); } stats.blocked = !isChecked; } }; } return null; } public static final AppFilter FILTER_APP_NOTIFICATION_RECENCY = new AppFilter() { @Override Loading
src/com/android/settings/applications/manageapplications/ApplicationViewHolder.java +2 −2 Original line number Diff line number Diff line Loading @@ -155,13 +155,13 @@ public class ApplicationViewHolder extends RecyclerView.ViewHolder { } } void updateSwitch(View.OnClickListener listener, boolean enabled, boolean checked) { void updateSwitch(Switch.OnCheckedChangeListener listener, boolean enabled, boolean checked) { if (mSwitch != null && mWidgetContainer != null) { mWidgetContainer.setOnClickListener(listener); mWidgetContainer.setFocusable(false); mWidgetContainer.setClickable(false); mSwitch.setFocusable(true); mSwitch.setClickable(true); mSwitch.setOnCheckedChangeListener(listener); mSwitch.setChecked(checked); mSwitch.setEnabled(enabled); } Loading
src/com/android/settings/applications/manageapplications/ManageApplications.java +1 −1 Original line number Diff line number Diff line Loading @@ -1505,7 +1505,7 @@ public class ManageApplications extends InstrumentedFragment switch (mManageApplications.mListType) { case LIST_TYPE_NOTIFICATION: holder.updateSwitch(((AppStateNotificationBridge) mExtraInfoBridge) .getSwitchOnClickListener(entry), .getSwitchOnCheckedListener(entry), AppStateNotificationBridge.enableSwitch(entry), AppStateNotificationBridge.checkSwitch(entry)); if (entry.extraInfo != null Loading
tests/robotests/src/com/android/settings/applications/AppStateNotificationBridgeTest.java +4 −6 Original line number Diff line number Diff line Loading @@ -53,6 +53,7 @@ import android.os.RemoteException; import android.os.UserHandle; import android.os.UserManager; import android.view.ViewGroup; import android.widget.CompoundButton; import android.widget.Switch; import com.android.settings.R; Loading Loading @@ -550,12 +551,10 @@ public class AppStateNotificationBridgeTest { } @Test public void testSwitchOnClickListener() { ViewGroup parent = mock(ViewGroup.class); public void testSwitchOnChangeListener() { Switch toggle = mock(Switch.class); when(toggle.isChecked()).thenReturn(true); when(toggle.isEnabled()).thenReturn(true); when(parent.findViewById(anyInt())).thenReturn(toggle); AppEntry entry = mock(AppEntry.class); entry.info = new ApplicationInfo(); Loading @@ -563,10 +562,9 @@ public class AppStateNotificationBridgeTest { entry.info.uid = 1356; entry.extraInfo = new NotificationsSentState(); ViewGroup.OnClickListener listener = mBridge.getSwitchOnClickListener(entry); listener.onClick(parent); CompoundButton.OnCheckedChangeListener listener = mBridge.getSwitchOnCheckedListener(entry); listener.onCheckedChanged(toggle, true); verify(toggle).toggle(); verify(mBackend).setNotificationsEnabledForPackage( entry.info.packageName, entry.info.uid, true); assertThat(((NotificationsSentState) entry.extraInfo).blocked).isFalse(); Loading
tests/robotests/src/com/android/settings/applications/manageapplications/ApplicationViewHolderTest.java +8 −3 Original line number Diff line number Diff line Loading @@ -35,6 +35,8 @@ import org.junit.runner.RunWith; import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; import java.util.concurrent.CountDownLatch; @RunWith(RobolectricTestRunner.class) public class ApplicationViewHolderTest { Loading Loading @@ -123,13 +125,16 @@ public class ApplicationViewHolderTest { @Test public void updateSwitch() { final CountDownLatch latch = new CountDownLatch(1); mView = ApplicationViewHolder.newView(new FrameLayout(mContext), true); mHolder = new ApplicationViewHolder(mView); mHolder.updateSwitch(v -> { } /* listener */, true, true); mHolder.updateSwitch((buttonView, isChecked) -> latch.countDown(), true, true); assertThat(mHolder.mSwitch.isChecked()).isTrue(); assertThat(mHolder.mSwitch.isEnabled()).isTrue(); assertThat(mHolder.mWidgetContainer.hasOnClickListeners()).isTrue(); assertThat(mHolder.mSwitch.isFocusable()).isTrue(); assertThat(mHolder.mSwitch.isClickable()).isTrue(); mHolder.mSwitch.callOnClick(); assertThat(latch.getCount()).isEqualTo(0); } }