Skip to content

Commit 7249e8a

Browse files
committed
Add a button to reset keystore
1 parent e6f0565 commit 7249e8a

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

src/processing/mode/android/AndroidKeyStore.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@ public static void generateKeyStore(String password,
6666
if(getKeyStore() == null) throw new Exception();
6767
}
6868

69+
public static boolean resetKeyStore() {
70+
File keyStore = getKeyStore();
71+
if(keyStore == null) return true;
72+
73+
File keyStoreBackup = new File(processing.app.Base.getSketchbookFolder(), "keystore/" + KEYSTORE_FILE_NAME + "-" + AndroidMode.getDateStamp());
74+
if(!keyStore.renameTo(keyStoreBackup)) return false;
75+
return true;
76+
}
77+
6978
private static String parseDnameField(String content) {
7079
if(content == null || content.length() == 0) return "Unknown";
7180
else return content;

src/processing/mode/android/KeyStoreManager.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public class KeyStoreManager extends JFrame {
2121
"http://developer.android.com/tools/publishing/app-signing.html#cert";
2222

2323
File keyStore;
24+
AndroidEditor editor;
2425

2526
JPasswordField passwordField;
2627
JPasswordField repeatPasswordField;
@@ -34,8 +35,15 @@ public class KeyStoreManager extends JFrame {
3435

3536
public KeyStoreManager(final AndroidEditor editor) {
3637
super("Android keystore manager");
38+
this.editor = editor;
3739

40+
createLayout();
41+
}
42+
43+
private void createLayout() {
3844
Container outer = getContentPane();
45+
outer.removeAll();
46+
3947
Box pain = Box.createVerticalBox();
4048
pain.setBorder(new EmptyBorder(13, 13, 13, 13));
4149
outer.add(pain);
@@ -86,13 +94,44 @@ public void actionPerformed(ActionEvent e) {
8694
});
8795
cancelButton.setEnabled(true);
8896

97+
JButton resetKeystoreButton = new JButton("Reset password");
98+
dim = new Dimension(Preferences.BUTTON_WIDTH*2,
99+
okButton.getPreferredSize().height);
100+
resetKeystoreButton.setPreferredSize(dim);
101+
resetKeystoreButton.addActionListener(new ActionListener() {
102+
public void actionPerformed(ActionEvent e) {
103+
setVisible(false);
104+
int result = Base.showYesNoQuestion(editor, "Android keystore",
105+
"Are you sure you want to reset the password?", "<html><body>We will have to reset the keystore to do this, " +
106+
"which means you won't be able to upload an update for your app signed with the new keystore to Google Play.<br/><br/>" +
107+
"We will make a backup for the old keystore.</body></html>");
108+
109+
if(result == JOptionPane.NO_OPTION) {
110+
setVisible(true);
111+
} else {
112+
if(!AndroidKeyStore.resetKeyStore()) {
113+
Base.showWarning("Android keystore", "Failed to remove keystore");
114+
setVisible(true);
115+
} else {
116+
keyStore = null;
117+
createLayout();
118+
}
119+
}
120+
}
121+
});
122+
resetKeystoreButton.setEnabled(true);
123+
89124
// think different, biznatchios!
90125
if (Base.isMacOS()) {
91126
buttons.add(cancelButton);
127+
128+
if(keyStore != null) buttons.add(resetKeystoreButton);
92129
// buttons.add(Box.createHorizontalStrut(8));
93130
buttons.add(okButton);
94131
} else {
95132
buttons.add(okButton);
133+
134+
if(keyStore != null) buttons.add(resetKeystoreButton);
96135
// buttons.add(Box.createHorizontalStrut(8));
97136
buttons.add(cancelButton);
98137
}

0 commit comments

Comments
 (0)