Remove mVideoPaused from VideoPreference
- We destoryed the MediaPlayer when VideoPreference is onPause(). When VideoPreference is onResumed, MediaPlayer always start from pause state, we don't need a data save/restore current video state. Bug: 143270527 Test: robolectric, manual Change-Id: I544e933e4237f6d92aeff8a7eb04b52e89d74a4a
This commit is contained in:
@@ -25,7 +25,7 @@
|
||||
android:key="security_settings_face_video"
|
||||
android:title="@string/summary_placeholder"
|
||||
app:animation="@raw/face_settings"
|
||||
app:controller="com.android.settings.biometrics.face.FaceSettingsVideoPreferenceController"/>
|
||||
app:controller="com.android.settings.widget.VideoPreferenceController"/>
|
||||
|
||||
<PreferenceCategory
|
||||
android:key="security_settings_face_unlock_category"
|
||||
|
@@ -259,7 +259,6 @@ public class FaceSettings extends DashboardFragment {
|
||||
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
|
||||
Lifecycle lifecycle) {
|
||||
final List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||
controllers.add(new FaceSettingsVideoPreferenceController(context));
|
||||
controllers.add(new FaceSettingsKeyguardPreferenceController(context));
|
||||
controllers.add(new FaceSettingsAppPreferenceController(context));
|
||||
controllers.add(new FaceSettingsRemoveButtonPreferenceController(context));
|
||||
|
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2019 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.settings.biometrics.face;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.widget.VideoPreference;
|
||||
import com.android.settings.widget.VideoPreferenceController;
|
||||
|
||||
/**
|
||||
* Preference controller for the video for face settings.
|
||||
*/
|
||||
public class FaceSettingsVideoPreferenceController extends VideoPreferenceController {
|
||||
|
||||
private static final String KEY_VIDEO = "security_settings_face_video";
|
||||
|
||||
private VideoPreference mVideoPreference;
|
||||
|
||||
public FaceSettingsVideoPreferenceController(Context context,
|
||||
String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
}
|
||||
|
||||
public FaceSettingsVideoPreferenceController(Context context) {
|
||||
this(context, KEY_VIDEO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mVideoPreference = screen.findPreference(KEY_VIDEO);
|
||||
mVideoPreference.onViewVisible(false /* paused */);
|
||||
}
|
||||
}
|
@@ -17,9 +17,7 @@
|
||||
package com.android.settings.gestures;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
@@ -27,21 +25,14 @@ import com.android.settings.R;
|
||||
import com.android.settings.core.TogglePreferenceController;
|
||||
import com.android.settings.widget.VideoPreference;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnCreate;
|
||||
import com.android.settingslib.core.lifecycle.events.OnPause;
|
||||
import com.android.settingslib.core.lifecycle.events.OnResume;
|
||||
import com.android.settingslib.core.lifecycle.events.OnSaveInstanceState;
|
||||
|
||||
public abstract class GesturePreferenceController extends TogglePreferenceController
|
||||
implements Preference.OnPreferenceChangeListener,
|
||||
LifecycleObserver, OnResume, OnPause, OnCreate, OnSaveInstanceState {
|
||||
|
||||
@VisibleForTesting
|
||||
static final String KEY_VIDEO_PAUSED = "key_video_paused";
|
||||
LifecycleObserver, OnResume, OnPause {
|
||||
|
||||
private VideoPreference mVideoPreference;
|
||||
@VisibleForTesting
|
||||
boolean mVideoPaused;
|
||||
|
||||
public GesturePreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
@@ -70,22 +61,9 @@ public abstract class GesturePreferenceController extends TogglePreferenceContro
|
||||
isChecked() ? R.string.gesture_setting_on : R.string.gesture_setting_off);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
if (savedInstanceState != null) {
|
||||
mVideoPaused = savedInstanceState.getBoolean(KEY_VIDEO_PAUSED, false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
outState.putBoolean(KEY_VIDEO_PAUSED, mVideoPaused);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
if (mVideoPreference != null) {
|
||||
mVideoPaused = mVideoPreference.isVideoPaused();
|
||||
mVideoPreference.onViewInvisible();
|
||||
}
|
||||
}
|
||||
@@ -93,7 +71,7 @@ public abstract class GesturePreferenceController extends TogglePreferenceContro
|
||||
@Override
|
||||
public void onResume() {
|
||||
if (mVideoPreference != null) {
|
||||
mVideoPreference.onViewVisible(mVideoPaused);
|
||||
mVideoPreference.onViewVisible();
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -20,7 +20,6 @@ import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.database.ContentObserver;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.provider.Settings;
|
||||
|
||||
@@ -35,15 +34,13 @@ import com.android.settings.widget.VideoPreference;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnCreate;
|
||||
import com.android.settingslib.core.lifecycle.events.OnPause;
|
||||
import com.android.settingslib.core.lifecycle.events.OnResume;
|
||||
import com.android.settingslib.core.lifecycle.events.OnSaveInstanceState;
|
||||
import com.android.settingslib.widget.RadioButtonPreference;
|
||||
|
||||
public class PreventRingingGesturePreferenceController extends AbstractPreferenceController
|
||||
implements RadioButtonPreference.OnClickListener, LifecycleObserver, OnSaveInstanceState,
|
||||
OnResume, OnPause, OnCreate, PreferenceControllerMixin {
|
||||
implements RadioButtonPreference.OnClickListener, LifecycleObserver,
|
||||
OnResume, OnPause, PreferenceControllerMixin {
|
||||
|
||||
@VisibleForTesting
|
||||
static final String KEY_VIBRATE = "prevent_ringing_option_vibrate";
|
||||
@@ -51,13 +48,11 @@ public class PreventRingingGesturePreferenceController extends AbstractPreferenc
|
||||
@VisibleForTesting
|
||||
static final String KEY_MUTE = "prevent_ringing_option_mute";
|
||||
|
||||
private final String KEY_VIDEO_PAUSED = "key_video_paused";
|
||||
private final String PREF_KEY_VIDEO = "gesture_prevent_ringing_video";
|
||||
private final String KEY = "gesture_prevent_ringing_category";
|
||||
private final Context mContext;
|
||||
|
||||
private VideoPreference mVideoPreference;
|
||||
private boolean mVideoPaused;
|
||||
|
||||
@VisibleForTesting
|
||||
PreferenceCategory mPreferenceCategory;
|
||||
@@ -109,11 +104,6 @@ public class PreventRingingGesturePreferenceController extends AbstractPreferenc
|
||||
return PREF_KEY_VIDEO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
outState.putBoolean(KEY_VIDEO_PAUSED, mVideoPaused);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRadioButtonClicked(RadioButtonPreference preference) {
|
||||
int preventRingingSetting = keyToSetting(preference.getKey());
|
||||
@@ -146,13 +136,6 @@ public class PreventRingingGesturePreferenceController extends AbstractPreferenc
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
if (savedInstanceState != null) {
|
||||
mVideoPaused = savedInstanceState.getBoolean(KEY_VIDEO_PAUSED, false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
if (mSettingObserver != null) {
|
||||
@@ -161,7 +144,7 @@ public class PreventRingingGesturePreferenceController extends AbstractPreferenc
|
||||
}
|
||||
|
||||
if (mVideoPreference != null) {
|
||||
mVideoPreference.onViewVisible(mVideoPaused);
|
||||
mVideoPreference.onViewVisible();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,7 +155,6 @@ public class PreventRingingGesturePreferenceController extends AbstractPreferenc
|
||||
}
|
||||
|
||||
if (mVideoPreference != null) {
|
||||
mVideoPaused = mVideoPreference.isVideoPaused();
|
||||
mVideoPreference.onViewInvisible();
|
||||
}
|
||||
}
|
||||
|
@@ -45,7 +45,6 @@ public class VideoPreference extends Preference {
|
||||
AnimationController mAnimationController;
|
||||
@VisibleForTesting
|
||||
boolean mAnimationAvailable;
|
||||
private boolean mVideoPaused;
|
||||
private float mAspectRatio = 1.0f;
|
||||
private int mPreviewId;
|
||||
private int mAnimationId;
|
||||
@@ -130,11 +129,16 @@ public class VideoPreference extends Preference {
|
||||
super.onDetached();
|
||||
}
|
||||
|
||||
public void onViewVisible(boolean videoPaused) {
|
||||
mVideoPaused = videoPaused;
|
||||
/**
|
||||
* Called from {@link VideoPreferenceController} when the view is onResume
|
||||
*/
|
||||
public void onViewVisible() {
|
||||
initAnimationController();
|
||||
}
|
||||
|
||||
/**
|
||||
* Called from {@link VideoPreferenceController} when the view is onPause
|
||||
*/
|
||||
public void onViewInvisible() {
|
||||
releaseAnimationController();
|
||||
}
|
||||
@@ -174,10 +178,6 @@ public class VideoPreference extends Preference {
|
||||
return mAnimationAvailable;
|
||||
}
|
||||
|
||||
public boolean isVideoPaused() {
|
||||
return mVideoPaused;
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the height of the video preference
|
||||
*
|
||||
|
@@ -29,7 +29,6 @@ public class VideoPreferenceController extends BasePreferenceController implemen
|
||||
LifecycleObserver, OnResume, OnPause {
|
||||
|
||||
private VideoPreference mVideoPreference;
|
||||
private boolean mVideoPaused;
|
||||
|
||||
public VideoPreferenceController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
@@ -50,7 +49,6 @@ public class VideoPreferenceController extends BasePreferenceController implemen
|
||||
@Override
|
||||
public void onPause() {
|
||||
if (mVideoPreference != null) {
|
||||
mVideoPaused = mVideoPreference.isVideoPaused();
|
||||
mVideoPreference.onViewInvisible();
|
||||
}
|
||||
}
|
||||
@@ -58,7 +56,7 @@ public class VideoPreferenceController extends BasePreferenceController implemen
|
||||
@Override
|
||||
public void onResume() {
|
||||
if (mVideoPreference != null) {
|
||||
mVideoPreference.onViewVisible(mVideoPaused);
|
||||
mVideoPreference.onViewVisible();
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -20,12 +20,10 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.reset;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
@@ -83,29 +81,15 @@ public class GesturePreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onResume_shouldStartVideoPreferenceWithVideoPauseState() {
|
||||
public void onResume_shouldStartVideoPreference() {
|
||||
final VideoPreference videoPreference = mock(VideoPreference.class);
|
||||
when(mScreen.findPreference(mController.getVideoPrefKey())).thenReturn(videoPreference);
|
||||
mController.mIsPrefAvailable = true;
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
final Bundle savedState = new Bundle();
|
||||
|
||||
mController.onCreate(null);
|
||||
mController.onResume();
|
||||
verify(videoPreference).onViewVisible(false);
|
||||
|
||||
reset(videoPreference);
|
||||
savedState.putBoolean(GesturePreferenceController.KEY_VIDEO_PAUSED, true);
|
||||
mController.onCreate(savedState);
|
||||
mController.onResume();
|
||||
verify(videoPreference).onViewVisible(true);
|
||||
|
||||
reset(videoPreference);
|
||||
savedState.putBoolean(GesturePreferenceController.KEY_VIDEO_PAUSED, false);
|
||||
mController.onCreate(savedState);
|
||||
mController.onResume();
|
||||
verify(videoPreference).onViewVisible(false);
|
||||
verify(videoPreference).onViewVisible();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -120,35 +104,6 @@ public class GesturePreferenceControllerTest {
|
||||
verify(videoPreference).onViewInvisible();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPause_shouldUpdateVideoPauseState() {
|
||||
final VideoPreference videoPreference = mock(VideoPreference.class);
|
||||
when(mScreen.findPreference(mController.getVideoPrefKey())).thenReturn(videoPreference);
|
||||
mController.mIsPrefAvailable = true;
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
when(videoPreference.isVideoPaused()).thenReturn(true);
|
||||
mController.onPause();
|
||||
assertThat(mController.mVideoPaused).isTrue();
|
||||
|
||||
when(videoPreference.isVideoPaused()).thenReturn(false);
|
||||
mController.onPause();
|
||||
assertThat(mController.mVideoPaused).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onSaveInstanceState_shouldSaveVideoPauseState() {
|
||||
final Bundle outState = mock(Bundle.class);
|
||||
|
||||
mController.mVideoPaused = true;
|
||||
mController.onSaveInstanceState(outState);
|
||||
verify(outState).putBoolean(GesturePreferenceController.KEY_VIDEO_PAUSED, true);
|
||||
|
||||
mController.mVideoPaused = false;
|
||||
mController.onSaveInstanceState(outState);
|
||||
verify(outState).putBoolean(GesturePreferenceController.KEY_VIDEO_PAUSED, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_preferenceSetCheckedWhenSettingIsOn() {
|
||||
// Mock a TwoStatePreference
|
||||
|
@@ -21,7 +21,6 @@ import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.anyBoolean;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -92,6 +91,6 @@ public class VideoPreferenceControllerTest {
|
||||
|
||||
mController.onResume();
|
||||
|
||||
verify(mPreference).onViewVisible(anyBoolean());
|
||||
verify(mPreference).onViewVisible();
|
||||
}
|
||||
}
|
||||
|
@@ -107,8 +107,6 @@ public class VideoPreferenceTest {
|
||||
|
||||
@Test
|
||||
public void onViewInvisible_shouldReleaseMediaplayer() {
|
||||
mVideoPreference.onViewVisible(false);
|
||||
|
||||
mVideoPreference.onViewInvisible();
|
||||
|
||||
verify(mAnimationController).release();
|
||||
|
Reference in New Issue
Block a user