1 package org.robolectric.android.controller; 2 3 import android.app.backup.BackupAgent; 4 import android.content.Context; 5 import org.robolectric.RuntimeEnvironment; 6 import org.robolectric.util.ReflectionHelpers; 7 8 public class BackupAgentController<T extends BackupAgent> extends 9 ComponentController<BackupAgentController<T>, T> { 10 private BackupAgentController(T backupAgent) { 11 super(backupAgent); 12 } 13 14 public static <T extends BackupAgent> BackupAgentController<T> of(T backupAgent) { 15 return new BackupAgentController<>(backupAgent).attach(); 16 } 17 18 private BackupAgentController<T> attach() { 19 if (attached) { 20 return this; 21 } 22 Context baseContext = RuntimeEnvironment.application.getBaseContext(); 23 ReflectionHelpers.callInstanceMethod(BackupAgent.class, component, "attach", 24 ReflectionHelpers.ClassParameter.from(Context.class, baseContext)); 25 return this; 26 } 27 28 @Override 29 public BackupAgentController<T> create() { 30 invokeWhilePaused("onCreate"); 31 return this; 32 } 33 34 @Override 35 public BackupAgentController<T> destroy() { 36 invokeWhilePaused("onDestroy"); 37 return this; 38 } 39 } 40