1 /* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.preload.actions; 18 19 import com.android.ddmlib.Client; 20 import com.android.ddmlib.IDevice; 21 import com.android.preload.ClientUtils; 22 import com.android.preload.DeviceUtils; 23 import com.android.preload.DumpData; 24 import com.android.preload.DumpTableModel; 25 import com.android.preload.Main; 26 27 import java.awt.event.ActionEvent; 28 import java.io.File; 29 import java.util.Date; 30 import java.util.Map; 31 32 public class WritePreloadedClassesAction extends AbstractThreadedDeviceSpecificAction { 33 private File preloadedClassFile; 34 WritePreloadedClassesAction(ClientUtils utils, IDevice device, DumpTableModel dataTableModel)35 public WritePreloadedClassesAction(ClientUtils utils, IDevice device, DumpTableModel dataTableModel) { 36 super("Write preloaded classes action", device); 37 } 38 39 @Override actionPerformed(ActionEvent e)40 public void actionPerformed(ActionEvent e) { 41 File[] files = Main.getUI().showOpenDialog(true); 42 if (files != null && files.length > 0) { 43 preloadedClassFile = files[0]; 44 super.actionPerformed(e); 45 } 46 } 47 48 @Override run()49 public void run() { 50 Main.getUI().showWaitDialog(); 51 try { 52 // Write the new file with a 5-minute timeout 53 DeviceUtils.overwritePreloaded(device, preloadedClassFile, 5 * 60); 54 } catch (Exception e) { 55 System.err.println(e); 56 } finally { 57 Main.getUI().hideWaitDialog(); 58 } 59 } 60 } 61